Results 1 to 6 of 6
Thread: Err in programm
- 12-26-2009, 08:10 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 33
- Rep Power
- 0
Err in programm
hi everybody
i have the project but can not run correct
Java Code:import java.util.*; import java.io.*; public class datamain{ //private static Scanner scan; public static void main (String[] args) throws IOException{ datafile ff=new datafile(); datafile2 ff2=new datafile2(); System.out.println ("======== Welcomr ============\n"); System.out.println (" 1-information"); System.out.println (" 2-information"); System.out.println (" 3-information"); System.out.println (" 4-Exit"); Scanner scan=new Scanner(System.in); int tni=scan.nextInt(); switch(tni){ case 1:info();break; //case 2:info();break; //case 3:info();break; case 4:System.exit(0); } ff2.vectt(); } public static void info () throws IOException{ for(int i=1;i<10;i++){ System.out.println (""); } Scanner scan=new Scanner(System.in); datafile ff=new datafile(); System.out.println ("Enter your name: "); String name1=scan.next(); ff.setname(name1); System.out.println ("Enter your Age: "); int age1=scan.nextInt(); ff.setAge(age1); System.out.println ("Enter your country: "); String country1=scan.next(); ff.setcountry(country1); } } ================== import java.util.*; import java.io.*; public class datafile{ private static String name; private static int Age; private static String country; public void setname(String name){ this.name=name; } public String getname(){ return name; } public void setAge(int Age){ this.Age=Age; } public int getAge(){ return Age; } public void setcountry(String country){ this.country=country; } public String getcountry(){ return country; } } ================== import java.util.*; import java.io.*; public class datafile2{ int div=3; File outFileName=new File("C:\\ali.txt"); Vector vect=new Vector(); datafile ff=new datafile(); public void vectt() { vect.add(ff.getname()); vect.add(ff.getAge()); vect.add(ff.getcountry()); /*for(int i=0;i<vect.size();i++){ System.out.println (vect.get(i)); }*/ try { BufferedWriter out = new BufferedWriter(new FileWriter(outFileName)); int count = 0 ; for(int index = 0 ; index < vect.size() ; index++ ){ out.write( vect.get(index).toString() +"," ); count++; if(count%div == 0) out.newLine(); } out.close(); } catch (IOException e) { System.out.print(e.getMessage()); } } }
i wrote this programm but no doing
-
What is the problem with your program?
* Does it compile?
* Does it run?
* Are you seeing any error messages?
If any errors, post them here as well as indicating which line is causing the error.
- 02-26-2010, 12:25 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 3
- Rep Power
- 0
Hey nassir, your local variable above in "datafile class" needs to be in lowercase as well as the parameters passed into these two methods above that you have posted.However,here is the problem below:
1)private static int Age;
2)public void setAge(int Age){
this.Age=Age;
}
3)public int getAge(){
return Age;
}
The corrected version should look similar like this inorder to compile and run your code:
1)private static int age;
2)private void setAge(int age){
this.age = age;
}
3)private int getAge(){
return age;
}
Thanks,
Jevy......
- 02-26-2010, 03:28 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Have you ever compile this code before write this complete code, I can see three classes there. Didn't you compile at least one of them before finalize the whole? If you comes with an error please let us know, without knowing that how can we comment on this pal. Good luck!
- 02-26-2010, 06:03 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 33
- Rep Power
- 0
Thank you for the good efforts
- 02-27-2010, 01:19 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you've found the solution for this, please mark the thread solved, from Thread Tools menu.
Similar Threads
-
Marks programm
By blackmoon in forum AWT / SwingReplies: 5Last Post: 12-08-2009, 10:06 PM -
[SOLVED] my programm doesn´t run like it shoud be.
By AlejandroPe in forum New To JavaReplies: 3Last Post: 04-07-2009, 12:42 PM -
web programm (.jsp)
By renars1985 in forum New To JavaReplies: 1Last Post: 12-18-2007, 03:23 PM -
web programm (.jsp)
By renars1985 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-18-2007, 08:34 AM -
Programm Error: cannot find symbol Help?
By junix in forum New To JavaReplies: 2Last Post: 12-10-2007, 05:30 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks