Solved

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

Posted on 2004-09-17
3
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 76
How  can  i  resolve  HTTP Status 404 -? 8 78
Chrome and Firefox Java 5 88
junit example issue 2 54
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

732 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