Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-08-2008, 06:45 AM
RavenNevarmore's Avatar
Member
 
Join Date: Oct 2008
Posts: 2
RavenNevarmore is on a distinguished road
Send a message via Skype™ to RavenNevarmore
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 06:58 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-08-2008, 07:55 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-08-2008, 08:18 AM
RavenNevarmore's Avatar
Member
 
Join Date: Oct 2008
Posts: 2
RavenNevarmore is on a distinguished road
Send a message via Skype™ to RavenNevarmore
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, 08:41 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-08-2008, 08:53 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,566
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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-26-2008 01:45 AM
Can't solve error message while looping BHCluster New To Java 15 04-22-2008 12:51 PM
java error message baileyr New To Java 2 01-23-2008 05:47 AM
Help with error message when running JAR via HTML file Simmy AWT / Swing 7 08-12-2007 05:47 PM
error message on jsp sandor Web Frameworks 1 04-11-2007 04:10 AM


All times are GMT +3. The time now is 11:46 AM.


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