Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-17
3
Medium Priority
?
198 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 200 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

722 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