• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in ArrayList and Enumeration program. need help please...

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone help me in debugging this code please. Its giving the error saying ; is expected for the end of while condition. I dont understand why.
import java.util.List;
import java.util.List.ArrayList;
import java.util.comparator;
import java.util.collections;
import java.util.Enumeration;

class Student{
private int sno;
private String sname;
Student(int i, String name)
{
sno = i;
sname = name;
}

public int getsno()
{

return sno;

}

public String getName()
{
return Sname;
}
} //end of Student
class ArrayListComparator
{
public static void main(String [] args)
{

List<Student> stu = new ArratList<Student>();
stu.add(new Student(1,"Siri"));
stu.add(new Student(2,"Shiva"));
stu.add(new Student(3,"Shruti"));
stu.add(new Student(4,"Sidd"));

Enumeration<Student> e = stu.elements();
While(e.hasMoreElements()) // giving an error here saying ; is expected
{
Student s = (Person)e.nextElement();
System.out.println("Stu No \t Stu Name");
System.out.println(s.getsno() +"\t" +s.getName());
}
}

Thank you

 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I debugged your code, there were a large no. of errors like While instead of while, spelling mistakes, illegal imports, wrong methods called i.e. there is nothing like elements() in a List.
I personally suggest, start using a IDE (Netbeans/Eclipse).

Here is your code corrected :

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Surana wrote:I debugged your code



Please don't do that. This site is NotACodeMill. The OP won't learn if others do his work for him.
 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Nitin. I debugged after correcting "While" to "while" and then it showed all the errors . It was not showing me the errors because of while --after fixing that I could see the many errors I made and could correct it. thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic