Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 122
Android development question 2 54
JavaFX TableView not displaying correctly 3 58
Java: The Public Class Main 4 32
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

831 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