Method Calls Inside a Java Class Return an "Identifier Expected After This Token" Error

Identifier expected error when calling a method in java

The code

CalibInit(checkboxWidget,hist1D); 

that is on a line of its own is not inside any of your methods. The compiler assumes that this is a new method declaration which is probably not what you want.

Side note:

It is not recommended to have methods starting with a upper case character: "Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized." from Code Conventions for the Java Programming Language

Resizing an ImageIcon

You need to put your code in a method, not directly in the class definition.

Try this for instance:

import java.awt.Image;
import javax.swing.ImageIcon;

public class Images
{
public static void main(String[] args) {
ImageIcon welcomeImage = new ImageIcon("WelcomeImage.PNG");
Image image = welcomeImage.getImage();
Image newImage = image.getScaledInstance(750, 500, java.awt.Image.SCALE_SMOOTH);//The error appears on this line
welcomeImage = new ImageIcon(newImage);
}
}

Syntax error on token close, Identifier expected after this token

Your

input.close();

at the end of the class is not in a method, this is not allowed in Java.

You need to move this to your main method. It should probably go after the end of your while loop as you have finished with input at that point:

   }   //END WHILE

input.close();

System.out.printf("\n%-30s%30s\n", "Total Number of Transactions", totalTrans);

Once you have done this you will find there are other compile errors which Eclipse can only detect when you have fixed the first error.

System.out.print( ); syntax error on token ., @ expected after this token

You need to put the code inside a method:

public class enc {
//The Look-Up Table with the position of all the available characters
public static final String LUT="*, .abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Input the sentence you want to encode.");
String s= sc.nextLine();
}
}


Related Topics



Leave a reply



Submit