illegal start of expression

Thread Solved

Join Date: Jan 2008
Posts: 36
Reputation: freddiecool is an unknown quantity at this point 
Solved Threads: 0
freddiecool's Avatar
freddiecool freddiecool is offline Offline
Light Poster

illegal start of expression

 
0
  #1
Jan 3rd, 2008
Hi can anyone help me i get an illegal start of expression public static void main everytime i try to compile.My code is below.
Thanks...

public static void main (String []args){
PrylDialog pd=new PrylDialog();
System.out.println("Welcome!!!!! ");
int option=0;
do{
option=pd.kommando();
switch(option){
case 1:pd.skapaPerson();
break;
case 2: pd.skapaPryl();
break;
case 3: pd.visaAlla();
break;
case 4: pd.visaRikast();
break;
case 5: pd.visaVissPerson();
break;
case 6: pd.börskrasch();
break;
case 7: System.out.println("That's all folks... ");
}
}
while (option!=7);
}
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 924
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 130
darkagn's Avatar
darkagn darkagn is offline Offline
Posting Shark

Re: illegal start of expression

 
0
  #2
Jan 3rd, 2008
Hi freddiecool and welcome to DaniWeb,

Not sure if this is your problem, but your variables should be initialised as private. ie:
  1. private pryDialog pd = new pryDialog();
  2. private int option = 0;
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2,108
Reputation: javaAddict is a splendid one to behold javaAddict is a splendid one to behold javaAddict is a splendid one to behold javaAddict is a splendid one to behold javaAddict is a splendid one to behold javaAddict is a splendid one to behold 
Solved Threads: 267
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Postaholic

Re: illegal start of expression

 
0
  #3
Jan 4th, 2008
At which line do you get the Error?
I murdered thousands for the Emperor and he gave me nothing except his damning silence. Now his lapdogs yap for every life I take, while the gods promise me the galaxy.
- Svane Vulfbad -
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 32
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: illegal start of expression

 
0
  #4
Jan 4th, 2008
Originally Posted by darkagn View Post
Hi freddiecool and welcome to DaniWeb,

Not sure if this is your problem, but your variables should be initialised as private. ie:
  1. private pryDialog pd = new pryDialog();
  2. private int option = 0;
No, those are local variables inside the method. They do not have access modifiers like "private".
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,639
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: illegal start of expression

 
0
  #5
Jan 4th, 2008
We need to see what comes directly before the method. That error normally occurrs because you've done something wrong before that, such as not closing a previous method, or forgetting a semicolon on the previous line, etc.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: uonsin is an unknown quantity at this point 
Solved Threads: 2
uonsin uonsin is offline Offline
Newbie Poster

Re: illegal start of expression

 
0
  #6
Jan 4th, 2008
you might want to check if the error is in pryDialog() because to me, your code should not give you an error
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,639
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: illegal start of expression

 
0
  #7
Jan 4th, 2008
Originally Posted by uonsin View Post
you might want to check if the error is in pryDialog() because to me, your code should not give you an error
That error is a compiler error, and as I have said, it is normally triggered by what came before. I.e. the previous method does not have a closing brace (so you then are effectively trying to declare a method within a method) or the last statement is missing the semicolon (which then means that the method declaration is effectively part of the previous statement) are the two main causes of this.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 924
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 130
darkagn's Avatar
darkagn darkagn is offline Offline
Posting Shark

Re: illegal start of expression

 
0
  #8
Jan 4th, 2008
Originally Posted by bugmenot View Post
No, those are local variables inside the method. They do not have access modifiers like "private".
Oops ... good point.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: freddiecool is an unknown quantity at this point 
Solved Threads: 0
freddiecool's Avatar
freddiecool freddiecool is offline Offline
Light Poster

Re: illegal start of expression

 
0
  #9
Jan 4th, 2008
This is my whole code, if anyone could spot the problem.Im not sure which line it is but it is an illegal start of expresion "public static void main(String []args){" at the end of the code.
(It is underlined). ^


import java.util.*;
import java.io.*;
import java.lang.*;

class PrylDialog {
ArrayList<Person> personer=new ArrayList<Person>();

Scanner scan=new Scanner(System.in);

String readString(String fraga){
System.out.print(fraga);
String str=scan.nextLine();
return str;
}

int readInt (String fraga){
for(;{

try{
System.out.print(fraga);
int x= Integer.parseInt(scan.nextLine());
return x;
}
catch (NumberFormatException e){
System.out.println("Fel - skall vara numerisk värde ");
}
}
}

Person getPerson(String na){
for (Person p : personer)
if (p.getNamn().equalsIgnoreCase(na))
return p;
return null;
}
Prylar getPrylar(String prylr){
for (Prylar pro : prylar)
if (pro.getPrylNamn().equalsIgnoreCase(prylr))
return pro;
return null;
}

int kommando(){
for(;{
int option=readInt("\n1 Skapa person\n2 Skapa pryl\n3 Visa alla\n4 Visa rikast\n5 Visa viss person\n6 Börskrasch\n7 Avsluta\n\n Ditt val: ");
if (option>=1 && option<=7)
return option;
else
System.out.println("Felaktig kommando, ska vara 1-7\\n");
}
}

void skapaPerson(){
String namn=readString("Namn: ");;
if (getPerson(namn)!=null){
System.out.println ("Person med namn-"+namn+" finns redan");
return;
}
Person pers= new Person(namn);
personer.add(pers);
}

void skapaPrylar(){
String pryl = readString("Vilken sorts pryl: ");
String namn = readString("Vilken person äger prylen: ");
Person p=getPerson(namn);
if (p==null){
System.out.println("Det finns inget person som heter "+namn);
return;
}

if (pryl.equalsIgnoreCase("Smycke")){
int v=readInt("Vikt: ");
int sten=readInt("Antal ädelstenar: ");
Smycke sm=new Smycke(pryl, v, sten);
getPerson(namn).prylar.add(sm);
}
else if (pryl.equalsIgnoreCase("apparater")){
int inkop =readInt("Pris: ");
int slit=readInt("Värde (1-10): ");
if (slit<1 && slit>10)
System.out.println("You Wroonnng FOOL!!!");
return;
Apparater ap= new Apparater(pryl, inkop, slit);
getPerson(namn).prylar.add(ap);
}
else if (pryl.equalsIgnoreCase("Aktie")){
int pris=readInt("Pris: ");
int antAkt=readInt("Antal aktier: ");
Aktie akt=new Aktie(pryl, antAkt, pris);
getPerson(namn).prylar.add(akt);
}

public static void main (String []args){
^

PrylDialog pd=new PrylDialog();
System.out.println("Welcome!!!!! ");
int option=0;
do{
option=pd.kommando();
switch(option){
case 1:pd.skapaPerson();
break;
case 2: pd.skapaPryl();
break;
case 3: pd.visaAlla();
break;
case 4: pd.visaRikast();
break;
case 5: pd.visaVissPerson();
break;
case 6: pd.börskrasch();
break;
case 7: System.out.println("That's all folks... ");
}
}

while(option !=7);

};
}
}


Ps. if you see a smiley in the code, it is a ';'.Not sure how to get rid of it.
thanks for the help.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,639
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: illegal start of expression

 
0
  #10
Jan 4th, 2008
your
  1. void skapaPrylar(){
method is not closed. add another
above the
  1. public static void main ....
line
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2871 | Replies: 17
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC