Results 1 to 2 of 2
- 09-25-2012, 01:45 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
No syntax errors, but run-time error exists?
//Class:
public class DigitExtractor {
//instance
private String digits;
private String array;
public DigitExtractor()
{
return;
}
public DigitExtractor(String digits)
{
this.digits=digits;
}
public String extract()
{
int diglength=digits.length();
for(int i = 0;i<(diglength-1);i++)
{
array=digits.substring(i);
}
return array;
}
}
//Tester
import java.util.Scanner;
public class DigitExtractorTester {
private static Scanner inputstring;
public static void main(String[] args)
{
System.out.println("type in #");
inputstring=new Scanner(System.in);
String digits=inputstring.toString();
DigitExtractor derp=new DigitExtractor(digits);
System.out.println(derp.extract());
}
}
//Output:
I expected the scanner to start, but it did not.
The console displayed:
type in # //from the System.out.println in the tester program
//and
E]
What does the "E]" mean?
-
Re: No syntax errors, but run-time error exists?
You're getting the toString() representation of a Scanner object, which is not what you want and which is not how you use a Scanner object.Java Code:String digits=inputstring.toString();
You may want to read the API entry for this or the tutorial. For my money, I'd use its nextLine() method. Also your extract() method doesn't make much sense to me.
It's a good lesson though: lack of syntax errors will only get you so far. The program still must make logical sense.
Similar Threads
-
Syntax Errors
By andimiami in forum New To JavaReplies: 8Last Post: 09-15-2011, 01:23 PM -
ClassNotFoundException error for a class that exists
By dahaka2011 in forum Sun Java Wireless ToolkitReplies: 1Last Post: 04-01-2011, 02:44 AM -
Eclipse is making me go silly with it's syntax errors
By magicmojo in forum New To JavaReplies: 5Last Post: 02-22-2011, 01:48 PM -
Run time errors
By crabman in forum New To JavaReplies: 6Last Post: 10-11-2009, 09:51 PM -
Cannot get passed these syntax errors
By MrKP in forum New To JavaReplies: 1Last Post: 05-12-2008, 07:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks