Jett
Jett

Reputation: 25

Help: Java error message re: incompatible types

I'm writing a program for my intro to Java class. I'm getting an error message, and I can't figure out what exactly it's telling me or how to resolve the issue. This is the message:

packageCost.java:17: incompatible types
found   : void
required: java.lang.String
                input = System.out.print("Please enter the weight of " +
                                        ^
packageCost.java:22: incompatible types
found   : void
required: java.lang.String
                input = System.out.print("How many miles is this " +
                                        ^
2 errors

Any help would be appreciated.

Upvotes: 0

Views: 4774

Answers (4)

Thuy
Thuy

Reputation: 1657

The Scanner won't work without declaring at the top of the document:

import java.util.Scanner;

Upvotes: 0

Andy
Andy

Reputation: 8949

Your attempting to assign a String to "System.out.print("Please enter..");

System.out.print returns "void" which is not String, thus incompatible types.

It looks like your trying to do console input. You could use a Scanner to do this.

Try something like

Scanner scanner = new Scanner(System.in);
System.out.println("Enter input: ");
String input = scanner.nextLine();

Read about Scanner class, Just google it.

Upvotes: 2

codaddict
codaddict

Reputation: 454950

System.out.print does not return anything and you are trying to collect its return value in a variable.

Upvotes: 3

irreputable
irreputable

Reputation: 45433

better:

String input = System.console().readLine("Please enter the ..");

Upvotes: 2

Related Questions