wood burning stoves*
The moose likes Java in General and the fly likes Can't understand complier error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can Watch "Can New topic
Author

Can't understand complier error

E Pease
Greenhorn

Joined: Mar 23, 2004
Posts: 15
I have the following program:

import javax.swing.*;
import javax.swing.JOptionPane;
import java.lang.*;

class Calc
{
public static void main ( String [] args )
{
String firstNum, secondNum;
int num1, num2, sum, product, difference, quotent;

// obtain the numbers from the user
firstNum = JOptionPane.showInputDialog( "Enter the first number: ");
secondNum = JOptionPane.showInputDialog( "Enter the second number: ");

// convert form String to int
num1 = Integer.parseInt( firstNum );
num2 = Integer.parseInt( secondNum );

// calculate the sum, product, difference, and quotent
sum = num1 + num2;
product = num1 * num2;
difference = num1 - num2;
quotent = num1 / num2;

// print out the sum, product, difference, quotent
JOptionPane.showMessageDialog( null, "The sum is " + sum, "Result", JOptionPane.Plain_Messge );

//System.out.println( "The sum is " + sum );
//System.out.println( "The product is " + product );
//System.out.println( "The difference is " + difference );
//System.out.println( "The quotent is " + quotent );

} // end main
} // end class Calc


And I get the following error message when I try to compile it:

.\Integer.java:3: <identifier> expected
publi static void main (String agrs[])

There are four other errors but this is the first one. I have tried renaming the class and file but I still get this message when I try to compile. I do not understand why it says there is no 'c' on the word public. I also do not know why it says 'String agrs[]' when my program says (String [] args). I do have a tendency to miss the small things but I am really stumped this time.


Thanks in advance.


SCJP 1.5 Beta (in progress, nature willing)
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there

When I take away the c in public and compile, I get the same error as you. Are you sure that your JDK is set up correctly? Can you compile other classes?

The only error that I get is on this line...
JOptionPane.showMessageDialog( null, "The sum is " + sum, "Result", JOptionPane.Plain_Messge );
You have spelt Plain_Messge wrong, it should be PLAIN_MESSAGE in caps.
E Pease
Greenhorn

Joined: Mar 23, 2004
Posts: 15
I changed the text to PLAIN_MESSAGE and I still get the same message. I am able to complie some programs but not a few. Could it hav something to do with the imports? The program below is one of the ones that run just fine.

/*
// // Java 109 : Networking with Java, by David Reilly
// // MyFirstInternetAddress
// // Displays the IP & hostname of localhost // // */
import java.io.*;
import java.net.*;
public class getIP {
public static void main(String args[])
{
try
{ InetAddress localaddr = InetAddress.getLocalHost();
System.out.println ("Local IP Address : " + localaddr );
System.out.println ("Local hostname : " + localaddr.getHostName());
}

catch (UnknownHostException e) {
System.err.println ("Can't detect localhost : " + e); } } }
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Perhaps you've got a funky control character embedded in your source file. This happens sometimes (although it used to happen a lot more in the good old days...

Try selecting and deleting that whole "public static void main" line, and retyping it.


[Jess in Action][AskingGoodQuestions]
E Pease
Greenhorn

Joined: Mar 23, 2004
Posts: 15
First let me start by thanking you guys for helping me out.

So, I reemoved the main line and replaced it. I neglected to put in the (String [] args) part before I recomplied it so I got the following error message:

// error message
Calc.java:6: '(' expected
{public static void main{

That made sence so I put in the (String [] args) between main and {. Then I recompiled the program and got the same error message as before:

// error message
.\Integer.java:3: ,identifier. expected
E Pease
Greenhorn

Joined: Mar 23, 2004
Posts: 15
Sorry, I accidentally posted before I was done.
So, then I created a folder in called test in the folder the original file had been saved in and saved the program in it. Then I recomplied it and it worked fine. I still do not know what the exact problem was but moving to the new folder seemed to fix it. Wierd. Thanks again for all of your help. I hope this thread is useful for others.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Thank you for sharing what you learned.

Note that you can edit your own posts. Just click on the icon that looks a little bit like a piece of paper.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can't understand complier error