Hi to all programmers..
i have a problem about this code .. i don't know what to do to this code.. i change a lot of code .. but always appear the error "illegal start of expression" .. I'm a newbie in Java.. please help me in this case.. thanks..

import javax.swing.*;
public class Change {

public static void main (String[]args)

{

String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a;
String[] m9= new String[15];
String[] m10= new String[15];import javax.swing.*; // (here) illegal start of exp.
public class Change { // (here) illegal start of exp. with ';' expected

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hi! Welcome to DaniWeb!

When Posting code please wrap the code in

tags so it's easier for people to read ^_^

As for your question, you can't declare a public class inside another class.  public means that the class can be accessed by any class.  Inner classes can not, they can only be accessed through the outer class.

Sun has a decent tutorial covering Nested Classes, and can explain better than I can:
http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html

Also, all import statements must be declared before the Outer class
[CODE="Java"]
import java.awt.Graphics;
import java.util.Random;

public class foo{
    //ACK!! Error!, can't import classes within a class
    import javax.swing.JFrame; 
}

But you don't need to import javax.swing.* again. imported classes can be accessed within nested classes as well.

Hope that helped!

Happy coding!

to: llemes4011

thanks for the feed back.. and it is a big help for me.. thanks again..
uhm.. the error exist again.. :( what i can do? this is the all program .. I'm dizzy in this code :( .. please help me again.. :)

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
public class Change {

public static void main (String[]args)

{

String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a;
String[] m9= new String[15];
String[] m10= new String[15];
public class foo{[B][I] // (here) illegal start of exp. and ';' expected[/I][/B]

public static void main (String[]args)

{

String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a, m13;
String[] m9= new String[10];
String[] m10= new String[10];
int[] m11= new int[10];
int[] m12= new int[10];

    do{
     m1 = JOptionPane.showInputDialog("Student Name:");
     m2 = JOptionPane.showInputDialog("Student ID:");
     m3 = JOptionPane.showInputDialog("Tuition Fee:");

     m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
     a  = Integer.parseInt(m0);
     {
        for(x=0; x<a; x++)

     m5 = JOptionPane.showInputDialog("Course Code:");
     m6 = JOptionPane.showInputDialog("Course Name:");
     m7 = JOptionPane.showInputDialog("Credit Hours:");
     m8 = JOptionPane.showInputDialog("Course GRADE:");
     m13 = Integer.parseInt(m7);

     }




























                JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);

                asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
                }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');   
        }

    }



int[] m11= new int[15];
int[] m12= new int[15];

    do{
     m1 = JOptionPane.showInputDialog("Student Name:");
     m2 = JOptionPane.showInputDialog("Student ID:");
     m3 = JOptionPane.showInputDialog("Tuition Fee:");

     m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
     a  = Integer.parseInt(m0);
     {
        for(x=0; x<a; x++)

     m5 = JOptionPane.showInputDialog("Course Code:");
     m6 = JOptionPane.showInputDialog("Course Name:");
     m7 = JOptionPane.showInputDialog("Credit Hours:");
     m8 = JOptionPane.showInputDialog("Course GRADE:");


     }




























                JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);

                asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
                }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');   
        }

    }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

O.o That's a lot a white space 0.0 In the future, try to write and post a simple example of what's wrong instead of posting your entire code.

public class Change {

    public static void main (String[]args){

    String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
    int x, a;
    String[] m9= new String[15];
    String[] m10= new String[15];
    public class foo{ // (here) illegal start of exp. and ';' expected

        public static void main (String[]args){

That's what you get when you format the code you posted correctly. It seems like you are trying to code a class inside a method, which isn't allowed in Java.

it should look something like this:

public class Change{
    // Classwide variables here can be accessed in class Foo
    public static void main(String[] args){
        Foo foo = new Foo(); //make an instance of the nested class
        foo.doSomething();  // Call a method like you normally would
    }
    static class Foo{ //note the lack of the "public" identifier here
        // The class has to be be static inorder to access it from a static method
        public void doSomething(){
            //do something
        }
    }
}

nested classes are tricky and should probably be avoided if you're new to java

sorry ..
hhhmm.. error's appear again.. hhmm
help me. :(

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
public class Change {
	
public static void main (String[]args){
  
  
String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a;
String[] m9= new String[15];
String[] m10= new String[15];
Foo foo = new Foo();
foo.doSomething();
static class foo{ // (here) illegal start of exp. and ';' expected.
	
public static void main (String[]args){

String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a, m13;
String[] m9= new String[10];
String[] m10= new String[10];
int[] m11= new int[10];
int[] m12= new int[10];

	do{
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	 {
	 	for(x=0; x<a; x++)
	 
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 m13 = Integer.parseInt(m7);
	 
	 }
	 

	 	
			    JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
			
		    	asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
				}while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');	
		}
		
	}
	 
	
	 	 
int[] m11= new int[15];
int[] m12= new int[15];

	do{
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	 {
	 	for(x=0; x<a; x++)
	 
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 
	 
	 }
	 
	
			    JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
			
		    	asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
				}while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');	
		}
		
	}

you don't want to declare class foo inside your main method. close the method before coding the foo class

you don't want to declare class foo inside your main method. close the method before coding the foo class

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
public class Change {
	
public static void main (String[]args){
  
  
String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a;
Foo foo = new Foo();
foo.doSomething();
static class foo{
	
public static void main (String[]args){

like that? hhmm.. then what is next? sorry if i have many question to you. hmm

yes, but after the foo.doSomething() line, put a "}" to close the method.

also, you don't want another main method inside class foo, call it something else, and it probably doesn't need the String[] args parameter either.

like that? .. the error exist now in other part of code.. :( ..
please teach me.. how to end it up..

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
public class Change {
	
public static void main (String[]args){
  
  
String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a;
Foo foo = new Foo();
foo.doSomething();
}
static class foo{
	
public static void main (String[]args){

String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
int x, a, m13;
String[] m9= new String[10];
String[] m10= new String[10];
int[] m11= new int[10];
int[] m12= new int[10];

	do{ 
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	 {
	 	for(x=0; x<a; x++)
	 
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 m13 = Integer.parseInt(m7);
	 
	 }
	 

	 	
			    JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
			
		    	asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
				}while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');	
		}
		
	}
	 
	
	 	 
int[] m11= new int[15];
int[] m12= new int[15];

	do{ //here illegal start of type
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	 {
	 	for(x=0; x<a; x++)
	 
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 
	 
	 }
	 
	
			    JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
			
		    	asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
		}while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y'); // here (identifier) expected	
		}
		
	} //here 'class or interface' expected

MonicaClare,
Did you find any solution?

nope..:( .. please help me in this case?

Here is error-free code. Did you wrote this code or copied?

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;

public class Change {
  public static void main (String[]args) {
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
      int x, a;
      Foo foo = new Foo();
      foo.main(null);
  }

  //  Static class 

  static class Foo{
   public static void main (String[]args){
       String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
       int x, a, m13;
       String[] m9= new String[10];
       String[] m10= new String[10];
       int[] m11= new int[10];
       int[] m12= new int[10];

	do{ 
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	 for(x=0; x<a; x++)
          {
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 m13 = Integer.parseInt(m7);
	 }
	 		               

JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
asa = JOptionPane.showInputDialog("try again? [Y/N] ...");

     }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');	
	 	 
       
    do{  
	 m1 = JOptionPane.showInputDialog("Student Name:");
	 m2 = JOptionPane.showInputDialog("Student ID:");
	 m3 = JOptionPane.showInputDialog("Tuition Fee:");
	 
	 m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
	 a  = Integer.parseInt(m0);
	  
 	for(x=0; x<a; x++)
	 {
	 m5 = JOptionPane.showInputDialog("Course Code:");
	 m6 = JOptionPane.showInputDialog("Course Name:");
	 m7 = JOptionPane.showInputDialog("Credit Hours:");
	 m8 = JOptionPane.showInputDialog("Course GRADE:");
	 }
	 
JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
 asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
	}while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');  

     }
   }
}

MonicaClare,
Don't post code again and again.
Compare the code posted at post #12 with your code.

MonicaClare,
Don't post code again and again.
Compare the code posted at post #12 with your code.

adatapost : thanks for helping me.. ^^

import javax.swing.*;
It must be at the top of your code not in the middle. What you have done is blunder. Change your code.
<snip fake signature>

the program is running .. but in the end ..
the note post .. what's that?
an error? hhmm.. i can't understand .. please help me..

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Change$Foo.main(Change.java:41)
at Change.main(Change.java:14)

When you try to convert a String to an int, you have to be careful. If you don't put a value in, or type a letter by mistake, it can lead to strange results. Try defaulting the JOptionPane's value at first, so if the user accidently hits ok or cancel before typing anything, it doesn't throw an error. checking after they enter wouldn't be a half-bad idea either. You do that with the JOptionPane.showInputDialog(null, String message, String title, int messageType) ;

Hope that helps!

try to check if you placed the do..while statement outside a class declaration. aybe you accidentally placed a closing brace leaving the statement declaration outside the class declaration

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
   
      public class Change {
      public static void main (String[]args) {
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a;
  
      Foo foo = new Foo();
      foo.main(null);
  
      }
     
  
      static class Foo{
      public static void main (String[]args){
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a, m13;
  
      String[] m9= new String[10];
      String[] m10= new String[10];
      int[] m11= new int[10];
      int[] m12= new int[10];  
  
    do{
  
      m1 = JOptionPane.showInputDialog("Student Name:");
      m2 = JOptionPane.showInputDialog("Student ID:");
      m3 = JOptionPane.showInputDialog("Tuition Fee:");  
  
      m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
      m13 = Integer.parseInt(m7);
  
      }
  
      JOptionPane.showInputDialog(null, String message, String title, int messageType); //here ")" expected
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
  
       
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
  
      do{
  
    m1 = JOptionPane.showInputDialog("Student Name:");
    m2 = JOptionPane.showInputDialog("Student ID:");
    m3 = JOptionPane.showInputDialog("Tuition Fee:");
  
        m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
  
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
  
      }
       
 JOptionPane.showInputDialog(null, String message, String title, int messageType); //here ")" expected
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
  
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
       
          }
 
        }

      }

like that?
the the error still exist.. :(
here:
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Change$Foo.main(Change.java:70)
at Change.main(Change.java:14)

..please help..

If you don't enter anything in the Textfield and press ok, or press cancel, it will give you that error.

This probably isn't what you're looking for, but read this article about JOptionPanes:
JOptionPanes

also, get rid of those lines that need the ), I posted those to show the syntax, not as actual code to use in the program.

.. thanks .. ^^
uuhhmm .. can i put string buffer here? .. if yes.. then how?
teach me.. please..

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
   
       
   
      public class Change {
      public static void main (String[]args) {
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a;
  
      Foo foo = new Foo();
      foo.main(null);
  
      }
     
  
      static class Foo{
      public static void main (String[]args){
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a, m13;
  
      String[] m9= new String[10];
      String[] m10= new String[10];
      int[] m11= new int[10];
      int[] m12= new int[10];
  
       
  
    do{
  
      m1 = JOptionPane.showInputDialog("Student Name:");
      m2 = JOptionPane.showInputDialog("Student ID:");
      m3 = JOptionPane.showInputDialog("Tuition Fee:");
      m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
      m13 = Integer.parseInt(m7);
  
      }
  
      JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
  
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
  
      do{
  
    m1 = JOptionPane.showInputDialog("Student Name:");
    m2 = JOptionPane.showInputDialog("Student ID:");
    m3 = JOptionPane.showInputDialog("Tuition Fee:");
    m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
  
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
  
      }
      
     JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
       
 
          }
 
        }

      }

A) If it works, mark the thread as solved.
B) If you have another question, unrelated to this thread, please start a new thread. StringBuffers have nothing to do with this thread.
C) A StringBuffer is irrelevant here. It is mainly used for adding onto the string, and I don't think you're foin that anywhere. If you really want to use one, look at the StringBuffer class in the Java API for how to use it.
D) You don't need to post all of your code every time. Post only the problem area, or write an example that demonstrates your problem. The above code seems to work fine as long as you enter a value into the JOptionPane.

This question has already been answered. Start a new discussion instead.