• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Can't understand complier error

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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); } } }
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
E Pease
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic