here's the complete lines of errors..
Exception in thread "main" java.util.NoSuc hElementExcepti on
at java.util.Strin gTokenizer.next Token(StringTok enizer.java:332 )
at CsvTest.readFil e(CsvTest.java: 26)
at Trial.main(Tria l.java:24)
I have no idea what to change here because I don't know what is wrong..please help me out... - import java.io.*;
-
import java.util.*;
-
import javax.swing.*;
-
-
-
public class Trial {
-
-
public static void main(String [] args) throws IOException {
-
-
BufferedReader s = null;
-
FileOutputStream out;
-
PrintStream p;
-
-
String CDtitle[] = new String[1000],
-
category[] = new String [1000],
-
container[] = new String [1000],
-
location[] = new String [1000];
-
-
int h, k, i=0,count=0, temporary;
-
String tmp, inputCDtitle, inputcategory, inputcontainer, inputlocation;
-
-
CsvTest test = new CsvTest();
-
test.readFile(CDtitle,category,container,location);
-
-
-
inputCDtitle = JOptionPane.showInputDialog("Enter item");
-
inputcategory = JOptionPane.showInputDialog("Enter Category");
-
inputcontainer = JOptionPane.showInputDialog("Enter container");
-
inputlocation = JOptionPane.showInputDialog("Enter location");
-
for(i=0;i<CDtitle.length;i++){
-
if (CDtitle[i]!=null){
-
-
System.out.println(CDtitle[i] + " = " + category[i]+ " = " + container[i]+ " = " + location[i]);
-
count++;
-
}
-
}
-
-
System.out.println(count);
-
CDtitle[count+1] = inputCDtitle;
-
category[count+1] = inputcategory;
-
container[count+1] = inputcontainer;
-
location[count+1] = inputlocation;
-
try {
-
out = new FileOutputStream("fileInput.txt");
-
p = new PrintStream(out);
-
-
for(h=0; h<CDtitle.length;h++){
-
if (CDtitle[h]!=null){
-
p.println(CDtitle[h]+ "," + category[h] + "," + container[h]+ "," + location[h]);
-
}
-
}
-
p.close();
-
-
-
} finally {
-
try {
-
if (s != null)
-
s.close();
-
}
-
catch (IOException ex) {
-
ex.printStackTrace();
-
}
-
-
}
-
test.readFile(CDtitle,category,container,location);
-
-
-
for(i=0;i<CDtitle.length;i++){
-
if (CDtitle[i]!=null){
-
System.out.println(CDtitle[i] + " = " + category[i]+ " = " + container[i]+ " = " + location[i]);
-
}
-
}
-
-
}
-
-
}
-
import java.io.BufferedReader;
-
import java.io.FileReader;
-
import java.io.FileNotFoundException;
-
import java.io.IOException;
-
import java.util.*;
-
-
public class CsvTest {
-
-
public void readFile(String CDtitle[],String category[], String container[], String location[]) {
-
-
BufferedReader br = null;
-
-
try {
-
-
br = new BufferedReader(new FileReader("fileInput.txt"));
-
String line = null;
-
int i=0;
-
while ((line = br.readLine()) != null) {
-
-
StringTokenizer st = new StringTokenizer(line, ",");
-
-
CDtitle[i] = st.nextToken();
-
category[i] = st.nextToken();
-
container[i] = st.nextToken();
-
location[i] = st.nextToken();
-
i++;
-
-
}
-
}
-
catch (FileNotFoundException ex) {
-
ex.printStackTrace();
-
}
-
catch (IOException ex) {
-
ex.printStackTrace();
-
}
-
finally {
-
try {
-
if (br != null)
-
br.close();
-
}
-
catch (IOException ex) {
-
ex.printStackTrace();
-
}
-
}
-
-
-
}
-
-
}
4 16729
Ive test your code,
There's nothing wrong with your code except that the file need for your program doesn't exist... At first execution...
I've test it in a single file,
Asking for Item, category, container and location in JOptionPane mode... -
import java.io.BufferedReader;
-
import java.io.FileReader;
-
import java.io.FileNotFoundException;
-
import java.io.IOException;
-
Is already been linked, since you have - import java.io.*;
-
import java.util.*;
-
import javax.swing.*;
You can erase it...
I am using jdk 1.6.03
And there is no problem... ;-)
Sukatoa, Shadow Shaman
1.) StringTokenizer is old. Use the String.split method instead.
2.) Arrays are not the best for object oriented modelling. Create a CD class with title, category e.t.c as fields and store them in an ArrayList<CD>.
3.) Do not use a FileOutputStrea m for writing characters. Use BufferedWriter or PrintWriter instead.
I've test it in a single file,
how do i test it in a single file?
how do i test it in a single file?
The codes above, i mean the code that you have been posted at the top...
Save them in a file, with filename exactly the same with the public class...
Don't forget to follow what r035198x said...
Update us,
Sukatoa...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Geetu |
last post by:
I am trying to jar up a file and getting this exception, not sure what
could be wrong. The same piece of code works fine in few machines but
there is one machine where this piece of code gives this exception ,
any help is very much appreciated, thanks
......java.util.zip.ZipExce
ption: duplicate entry: META-INF/
java.util.zip.ZipException: duplicate entry: META-INF/
at
java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:160)...
|
by: daniel li |
last post by:
I got another convert issue. This is the same project as I posted
yesterday, and received a perfect response.
The conversion threw a SupportClass for me and one of the data type is
CollectionSupport, this is to my understanding to replace
Java.Util.Collection. In my code:
public EcomWeb.rx_transactions.order.GroverOrder
getGroverOrders(EcomWeb.domain.WebOrder webOrder)
{
System.Console.Out.WriteLine("OrderFactory.
getGroverOrders( )...
|
by: puntino |
last post by:
Hi
I have created my Alarm, at compile time I don't have any problem, but at run time I receive the follo wing messages:
Exception in thread "main" java.lang.NullPointerException
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.scheduleAtFixedRate(Unknown Source)
at Alarm.AlarmExecute(Alarm.java:20)
at Test.main(Test.java:11)
(With <- I have pointed out the line 11 of test.java and line 20 of alarm.java)
|
by: Dameon99 |
last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the class: (one I added all the asteriss to.
// If we are at the end of input then NoSuchElement;
// If there is still input left then InputMismatch
private void throwFor() {
skipped = false;
if ((sourceClosed) &&...
|
by: jri |
last post by:
Hello,
I got an assignement for school where I have to make a game with matches.
This is what I got:
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Lucifer
| |
by: oll3i |
last post by:
when i run my jsp file i get an error
SEVERE: Servlet.service() for servlet jsp threw exception
java.util.MissingResourceException: Can't find bundle for base name MessagesBundle, locale pl_PL
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1508)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1262)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:789)
at...
|
by: sukatoa |
last post by:
This was my first time to encouter this kind of exception....
that exception appears when i invoked the the method below.
private final String encrypting(String enc){
int declen=array1.length;
String temp=enc;
for(int x=-1;x++<declen;){
temp=temp.replaceAll(String.valueOf(array2),String
.valueOf(array1));
|
by: jimgym1989 |
last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException
this is my code
/**
* @(#)textFileRead.java
*
*
* @author
* @version 1.00 2008/10/17
*/
|
by: monkey0525 |
last post by:
Each time I run the ProgTwo program, it displays:
1. Display one product
2. Display all products
3. Add a new CD
6. Exit
Enter your choice: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |