Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-08-2008, 04:45 AM
RavenNevarmore's Avatar
Member
 
Join Date: Oct 2008
Posts: 2
Rep Power: 0
RavenNevarmore is on a distinguished road
Send a message via Skype™ to RavenNevarmore
Exclamation Error Message in JBuilder
Alright, so I'm pretty new here and new to Java, and I'm sitting here working on my homework and I think that I've got the code correct, but I keep getting this error on my program:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

The Program itself looks like this:

Code:
import javax.swing.JOptionPane;
public class study2 {

	public static void main(String[] args) {
		String temp1 , temp2;
		int num1 , num2, max = 0;
		String choice="";
			
		do{
			JOptionPane.showInputDialog("The First Number is:");
				num1 = Integer.parseInt(temp1);
			JOptionPane.showInputDialog("The Second Number is:");
				num2 = Integer.parseInt(temp2);
			
				if (num1 > num2)
					max = num1;
				else max = num2;
				
			JOptionPane.showMessageDialog(null,"The Maximum is" +max);
			JOptionPane.showInputDialog(null, "Would you like to continue?: ");
					
				} while (choice.equals("yes")||choice.equals("Yes"));
			 
			 
		}
		
		

	}


I would immensely appreciate any help on this error, or how to fix whatever I did wrong.

Last edited by RavenNevarmore; 10-08-2008 at 04:58 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-08-2008, 05:55 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,522
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Are you sure that your code is correct. I don't think so.

You have declared two String variables temp1 and temp2. You use them inside the main method without initialization. That's why you get compilation error in your code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-08-2008, 06:18 AM
RavenNevarmore's Avatar
Member
 
Join Date: Oct 2008
Posts: 2
Rep Power: 0
RavenNevarmore is on a distinguished road
Send a message via Skype™ to RavenNevarmore
Default
Then how do I 'initilize' these variables? I thought that all I had to do to use a variable was to declare it.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-08-2008, 06:41 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,522
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
If you are using local variables, you must declare them before use. For instance/class variables you don't need to do it, default values are automatically declared.

Code:
			temp1 = JOptionPane.showInputDialog("The First Number is:");
				num1 = Integer.parseInt(temp1);
			temp2 = JOptionPane.showInputDialog("The Second Number is:");
				num2 = Integer.parseInt(temp2);
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-08-2008, 06:53 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,522
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Here is much better code segment. Write it just for fun. Try to learn something on that pal, but I'm not superior on Java.

Code:
import javax.swing.JOptionPane;

public class study2 {

    public static void main(String[] args) {
        String temp1 = null , temp2 = null;
        int num1 = 0 , num2 = 0, max = 0;
        int ret = 0;
        
        inner: do {
            try {
                temp1 = JOptionPane.showInputDialog("The First Number is:");
                num1 = Integer.parseInt(temp1);

                temp2 = JOptionPane.showInputDialog("The Second Number is:");
                num2 = Integer.parseInt(temp2);
            }
            catch(NumberFormatException ex) {
                JOptionPane.showMessageDialog(null, "Invalid input");
                continue inner;
            }
            if (num1 > num2)
                max = num1;
            else 
                max = num2;

            JOptionPane.showMessageDialog(null,"The Maximum is " +max);
            ret = JOptionPane.showConfirmDialog(null, "Continue?", "More", 
                    JOptionPane.YES_NO_OPTION , JOptionPane.INFORMATION_MESSAGE);

        } while(ret == JOptionPane.YES_OPTION);
    }

}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange Error message little_polarbear New To Java 4 08-25-2008 11:45 PM
Can't solve error message while looping BHCluster New To Java 15 04-22-2008 10:51 AM
java error message baileyr New To Java 2 01-23-2008 03:47 AM
Help with error message when running JAR via HTML file Simmy AWT / Swing 7 08-12-2007 03:47 PM
error message on jsp sandor Web Frameworks 1 04-11-2007 02:10 AM


All times are GMT +2. The time now is 06:17 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org