6 Replies - 887 Views - Last Post: 10 September 2013 - 10:34 PM Rate Topic: -----

#1 jphoc13  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 194
  • Joined: 08-July 13

JOptionPane typo

Posted 09 September 2013 - 10:15 PM

I have the typical miles per gallon assignment. And I don't want the homework done for me just curious what my errors are so far. I know I need to convert to int, and put the formula in later once I get that far. I am getting errors at the parts I bolded in Netbeans. This is my first semester so be gentile and don't think I am an idiot please :)

<code>
import javax.swing.JOptionPane;





public class MilesPerGallon {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String milesDriven; //The miles driven by user
String gallonsUsed; //The gallons used by user
//Get the users milesDriven
String inputString = JOptionpane.showInputDialog ("Miles Driven are ");
//Convert the input to a int.
milesDriven = Integer.parseInt(inputString);
//Get the users gallonsUsed
inputString = JOptionpane.showInputDialog ("Gallons used are ");
//Display milesPerGallon
JOptionPane.showMessageDialog(null, );
</code>

Getting these errors in order: incompatible types, required string, found int

the assigned value is never used

Illegal start of expression.

Is This A Good Question/Topic? 0
  • +

Replies To: JOptionPane typo

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9497
  • View blog
  • Posts: 35,844
  • Joined: 12-June 08

Re: JOptionPane typo

Posted 09 September 2013 - 11:29 PM

moving to java..
Was This Post Helpful? 1
  • +
  • -

#3 salazar  Icon User is offline

  • D.I.C Addict

Reputation: 87
  • View blog
  • Posts: 539
  • Joined: 26-June 13

Re: JOptionPane typo

Posted 09 September 2013 - 11:51 PM

In the first error, check if your milesDriven variable is an int. The compiler is complaining about your types. The types must match. It is saying the variable you are assigning to expects a type 'a' but you are assigning type 'b'.

The second is a bit easier. This is not an actual error. It is just that some editors make sure you follow good practices. In this case, it is telling you about assigning a value to a variable that you never use, which makes the assigning pointless.

Finally, in this error, you have the extra comma following the null. Since the method takes more then one parameter, you probably need to supply more parameters. Hope this helps.
Was This Post Helpful? 2
  • +
  • -

#4 jphoc13  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 194
  • Joined: 08-July 13

Re: JOptionPane typo

Posted 10 September 2013 - 05:57 AM

View Postsalazar, on 09 September 2013 - 11:51 PM, said:

In the first error, check if your milesDriven variable is an int. The compiler is complaining about your types. The types must match. It is saying the variable you are assigning to expects a type 'a' but you are assigning type 'b'.

The second is a bit easier. This is not an actual error. It is just that some editors make sure you follow good practices. In this case, it is telling you about assigning a value to a variable that you never use, which makes the assigning pointless.

Finally, in this error, you have the extra comma following the null. Since the method takes more then one parameter, you probably need to supply more parameters. Hope this helps.

Awesome thanks!
Was This Post Helpful? 0
  • +
  • -

#5 jphoc13  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 194
  • Joined: 08-July 13

Re: JOptionPane typo

Posted 10 September 2013 - 09:46 PM

Okay so when I compile it, it shows the build as successful but when I run it I get this:

Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
at JOptionpane.showInputDialog(JOptionpane.java:13)
at MilesPerGallon.main(MilesPerGallon.java:21)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


Here is the code:
<code>

import javax.swing.JOptionPane;





public class MilesPerGallon {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String inputString; //For reading input
int milesDriven; //The miles driven by user
int gallonsUsed; //The gallons used by user
double milesPerGallon;

//Get the users milesDriven
inputString = JOptionpane.showInputDialog ("Miles Driven are ");

//Convert the input to an int.
milesDriven = Integer.parseInt(inputString);

//Get the users gallonsUsed
inputString = JOptionpane.showInputDialog ("Gallons used are ");

gallonsUsed = Integer.parseInt(inputString);

//Calculate the milesPerGallon
milesPerGallon = milesDriven / gallonsUsed;

//Display milesPerGallon
JOptionPane.showMessageDialog(null, "Your miles per gallon is " + milesPerGallon);
}
}

Any help would be awesome. I will try to find the answer on my own of course but have no idea what this error is telling me and googling it hasn't shed any light on it either.
Was This Post Helpful? 0
  • +
  • -

#6 salazar  Icon User is offline

  • D.I.C Addict

Reputation: 87
  • View blog
  • Posts: 539
  • Joined: 26-June 13

Re: JOptionPane typo

Posted 10 September 2013 - 10:23 PM

It's because of a typo. It should be 'JOptionPane' instead of 'JOptionpane'. Java is case-sensitive. Those two are different.
Was This Post Helpful? 1
  • +
  • -

#7 jphoc13  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 194
  • Joined: 08-July 13

Re: JOptionPane typo

Posted 10 September 2013 - 10:34 PM

View Postsalazar, on 10 September 2013 - 10:23 PM, said:

It's because of a typo. It should be 'JOptionPane' instead of 'JOptionpane'. Java is case-sensitive. Those two are different.

Oh wow! Can't believe I missed that. I stared at that screen for hours!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1