Solved

compile error:  incompatable types___found: void___required: java.lang.String

Posted on 2004-09-17
3
166 Views
Last Modified: 2012-05-05
The Situation:
New Java coder.
Writing a class where user inputs weight in pounds or kilos then converts to pounds or kilos.

The Code:
public void set()
{
     //input and report units
     //loop till k or p is entered
     do
     {
          x = JOptionPane.showMessageDialog (null, "Is the weight measured in Kilograms (input K) or Pounds (input P)?");
          unitReply = x.charAt(0);

The Compile error:
incompatible types
found   : void
required: java.lang.String
x = JOptionPane.showMessageDialog (null, "Is the weight measured in
                                                      ^
Kilograms (input K) or Pounds (input P)?");

What is the problem?

smkJackstraw
                                                         
0
Comment
Question by:smkJackstraw
  • 3
3 Comments
 
LVL 3

Accepted Solution

by:
CI-Ia0s earned 50 total points
ID: 12089700
showMessageDialog doesn't return anything, ie. void. You want showInputDialog.
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12089703
Also, with showInputDialog it would be:
x = JOptionPane.showInputDialog("Is the weight measured in Kilograms (input K) or Pounds (input P)?");

No "null" with showInputDialog.
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12089739
P.S. A note of caution to a new programmer: choosing variables with names such as "x" will come back to haunt you later on. When you get to writing programs with dozens or even hundreds of variables you'll start forgetting which are which. It's better to have a more informative variable name, such as "weightUnit", etc.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now