Solved

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

Posted on 2004-09-17
3
169 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 89
eclipse java  build path 6 44
jar file executable 12 39
servlet example issue 6 30
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

27 Experts available now in Live!

Get 1:1 Help Now