MISSING RETURN STATEMENT
Page 1 of 110 Replies - 366 Views - Last Post: 09 October 2012 - 11:27 AM
#1
MISSING RETURN STATEMENT
Posted 09 October 2012 - 10:53 AM
package scvprocessor.another.version;
import java.util.Scanner;
/**
*
* @author c2rsaldi
*/
public class SCVProcessorAnotherVersion {
static Scanner message = new Scanner(System.in);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Type a command");
String inputMessage = message.nextLine();
inputText (inputMessage) ;
System.out.println(inputText (inputMessage));
// TODO code application logic here
}
public static String inputText (String inputMessage) {
// here is a mistake (missing return statement)
if (inputMessage.contains("print")) {
return inputMessage +"\n"+"Print Command";
} else if (inputMessage.contains("save")) {
return inputMessage + "\n"+"Save Command";
}
else if (inputMessage.contains("=")) {
return inputMessage+"\n"+"Assignment command";
} else if (inputMessage.contains("exit")) {
return inputMessage+"\n"+"Exit command";
Replies To: MISSING RETURN STATEMENT
#2
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 10:58 AM
#3
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:01 AM
jdavi134, on 09 October 2012 - 10:58 AM, said:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing return statement
at scvprocessor.another.version.SCVProcessorAnotherVersion.inputText(SCVProcessorAnotherVersion.java:24)
at scvprocessor.another.version.SCVProcessorAnotherVersion.main(SCVProcessorAnotherVersion.java:20)
Java Result: 1
#4
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:04 AM
#5
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:04 AM
If I pass a string that contains none of those strings, what happens? That's what you need to answer.
This post has been edited by Zoquo: 09 October 2012 - 11:09 AM
#6
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:09 AM
Zoquo, on 09 October 2012 - 11:04 AM, said:
package scvprocessor.another.version;
import java.util.Scanner;
public class SCVProcessorAnotherVersion {
static Scanner message = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Type a command");
String inputMessage = message.nextLine();
inputText (inputMessage) ;
System.out.println(inputText (inputMessage));
}
public static String inputText (String inputMessage) {
if (inputMessage.contains("print")) {
return inputMessage +"\n"+"Print Command";
} else
if (inputMessage.contains("save")) {
return inputMessage + "\n"+"Save Command";
}
else
if (inputMessage.contains("=")) {
return inputMessage+"\n"+"Assignment command";
} else
if (inputMessage.contains("exit")) {
return inputMessage+"\n"+"Exit command";
}
}
}
sorry, I am new in Java ;( I have 4 RETURNS in method inputText. I thought that is enough ...
#7
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:13 AM
#8
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:16 AM
#9
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:21 AM
#10
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:24 AM
} else {
return inputMessage+"\n"+"Unknown command";
}
This post has been edited by grimpirate: 09 October 2012 - 11:24 AM
#11
Re: MISSING RETURN STATEMENT
Posted 09 October 2012 - 11:27 AM
|
|

New Topic/Question
Reply



MultiQuote




|