| | |
Need help in code
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 0
I am new at java.
I am making an address book program.
Below is a code of the Search class.
Could anyone please look into it?
The program is giving a problem while runtime.
Help will be highly appreciated.
I am making an address book program.
Below is a code of the Search class.
Could anyone please look into it?
The program is giving a problem while runtime.
Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; class search { private String str,sval; private String arr[]=new String[8]; char ch1='y',ch2; private int n,ctr; clear c1=new clear(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void calc()throws IOException { DataInputStream in=new DataInputStream(new FileInputStream("adbk.txt")); //file read System.out.println("How would you like to search?"); System.out.println("1)by fn"); System.out.println("2)by ln"); System.out.println("3)by area code"); System.out.println("4)by city"); System.out.println("5)by state"); System.out.println("enter choice:"); n=Integer.parseInt(br.readLine())-1; c1.clr(); //clr here switch(n) { case 1: { System.out.println("enter fn"); } case 2: { System.out.println("enter ln"); } case 3: { System.out.println("enter arcd"); } case 4: { System.out.println("enter city"); } case 5: { System.out.println("enter state"); } default: { System.out.println("error"); break; } } sval=br.readLine(); c1.clr(); //clr here while(in.available()!=0) { str=in.readLine(); StringTokenizer st=new StringTokenizer(str," "); for(int i=0;i<8;i++) { arr[i]=st.nextToken(); } if(sval==arr[n]) { ctr++; for(int i=0;i<8;i++) { System.out.print(arr[i]+" "); System.out.println(); } } } System.out.println("Total hits="+ctr); } public static void main(String args[]) { search s=new search(); try { s.calc(); } catch(IOException e) { System.out.println("error"); } } }
What are the error messages? Post the whole stack.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
You really should change to
Java Syntax (Toggle Plain Text)
System.out.println("error");
Java Syntax (Toggle Plain Text)
e.printStackTrace();
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 0
Sir,
I tried the ,instead of But now I get a compile time error as follows:
C:\Documents and Settings\comp1\My Documents\search.java:49: cannot resolve symbol
symbol : variable e
location: class search
e.printStackTrace();
I tried the
Java Syntax (Toggle Plain Text)
e.printStackTrace();
Java Syntax (Toggle Plain Text)
System.out.println("error");
C:\Documents and Settings\comp1\My Documents\search.java:49: cannot resolve symbol
symbol : variable e
location: class search
e.printStackTrace();
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 0
This is the modified code.
It is not working properly.
Please look into it.
It is not working properly.
Please look into it.
Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; class search { private String str,sval; private String arr[]=new String[8]; char ch1='y',ch2; private int n,ctr; clear c1=new clear(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void calc()throws IOException { DataInputStream in=new DataInputStream(new FileInputStream("adbk.txt")); //file read System.out.println("How would you like to search?"); System.out.println("1)by fn"); System.out.println("2)by ln"); System.out.println("3)by area code"); System.out.println("4)by city"); System.out.println("5)by state"); System.out.println("enter choice:"); n=Integer.parseInt(br.readLine()); //clr here switch(n) { case 1: { System.out.println("enter fn"); break; } case 2: { System.out.println("enter ln"); break; } case 3: { System.out.println("enter arcd"); break; } case 4: { System.out.println("enter city"); break; } case 5: { System.out.println("enter state"); break; } default: { System.out.println("error"); break; } } sval=br.readLine(); while(in.available()!=0) { str=in.readLine(); StringTokenizer st=new StringTokenizer(str," "); for(int i=0;i<8;i++) { arr[i]=st.nextToken(); } if(sval==arr[n]) { ctr++; for(int i=0;i<8;i++) { System.out.print(arr[i]+" "); System.out.println(); } } } System.out.println("Total hits="+ctr); } public static void main(String args[]) { search s=new search(); try { s.calc(); } catch(IOException e) { e.printStackTrace(); } } }
•
•
Join Date: Oct 2008
Posts: 25
Reputation:
Solved Threads: 0
The error i get while runtime is as follows:
What does this indicate?
Java Syntax (Toggle Plain Text)
Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:232) at search.calc(search.java:70) at search.main(search.java:93)
What does this indicate?
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: Collision Detection - Micro Java
- Next Thread: printing an element in an array
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jmf jni jpanel julia linux list loop loops mac map method methods mobile netbeans newbie number online oracle page parameter plazmic print problem program programming project recursion reporting rotatetext scanner screen sell server set size sms socket sort sourcelabs sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working






