• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can't run my program i get errors.  RSS feed

 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this is the objective of the program.

The following pseudocode describes how to turn a string containing a ten-digit phone number (such as "4155551212") into a more readable string with parentheses and dashes, like this: "(415) 555-1212".

Take the substring consisting of the first three characters and surround it with "(" and ") ". This is the area code.
Concatenate the area code, the substring consisting of the next three characters, a hyphen, and the substring consisting of the last four characters. This is the formatted number.

Translate this pseudocode into a Java program that reads a telephone number into a string variable, computes the formatted number, and prints it.


i
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get errors.

Please copy the full text of the error message and paste it here. It has important info about the error.

Note: The code should test the length of the String that was read to make sure it has 10 characters. See the String class's API doc.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: <any>
Enter a 10-digit phone number: at ReadPhone.main(ReadPhone.java:11)
Java Result: 1

this is what i receive
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous ctor sym type: <any>
Enter a 10-digit phone number: at ReadPhone.main(ReadPhone.java:11)

Line 11 compiles without errors for me.

I'm confused about how the error message is mixed in with the print out from the program.

Is the posted code what you are working with? Or is there another version?

Use the javac program to compile your code for better error messages.
Or learn how to use your IDE to find syntax errors.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get errors on line 11: BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

line 13 and 14:String phone = null;
String newphone= null;

line 17: newphone = "(" + phone.Substring(0,3) + ") " + phone.Substring(3,6) + "-" + phone.Substring(6) );

i get error messages on the following lines. these lines are the ones that are not letting my program run.

i am using netbeans.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get errors

Can you copy the full text errors from the compiler and paste them here?

Use the javac program to compile your code for better error messages.
Or learn how to use your IDE to find syntax errors.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ReadPhone.java:17: error: ';' expected
newphone = "(" + phone.Substring(0,3) + ") " + phone.Substring(3,6) + "-" + phone.Substring(6) );
^
1 error
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Look above where the ^ is located. A String's definition doesn't end with a )
If the ) is part of the String it should be enclosed in"s like this ")"
If not, it should be removed.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


thats what i revised it too

now i got this errors

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

----jGRASP exec: javac -g ReadPhone.java
ReadPhone.java:11: error: cannot find symbol
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
^
symbol: class InputStreamReader
location: class ReadPhone
ReadPhone.java:17: error: cannot find symbol
newphone = (" + phone.Substring(0,3) + ") + phone.Substring(3,6) + "-" + phone.Substring(6);
^
symbol: method Substring(int,int)
location: variable phone of type String
ReadPhone.java:17: error: cannot find symbol
newphone = (" + phone.Substring(0,3) + ") + phone.Substring(3,6) + "-" + phone.Substring(6);
^
symbol: method Substring(int)
location: variable phone of type String
3 errors
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ReadPhone.java:11: error: cannot find symbol
ReadPhone.java:11: error: cannot find symbol
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
^
symbol: class InputStreamReader

The compiler can not find a definition for the InputStreamReader class. Make sure you have spelled it correctly and that there is an import statement for it.

ReadPhone.java:17: error: cannot find symbol
newphone = (" + phone.Substring(0,3) + ") + phone.Substring(3,6) + "-" + phone.Substring(6);
^
symbol: method Substring(int,int)
location: variable phone of type String

Check the spelling. Method names start with lowercase letters.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I REVISED it



 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to use java.util.Scanner to read input rather than BufferedReader.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NR: I changed the orange text to underlined; beware of text colours. Some people find certain colours difficult to read. The orange is particularly difficult because it is too pale.
That looks like the output from an IDE; if I use Eclipse, the output from System.err appears in red; since System.err and System.out can use separate threads to run, their outputs can be interspersed with each other. The answer is to look for the compiler errors first. In Eclipse they are marked with red triangles and the run dialogue tells you specifically that there are errors before it tries to compile the program. Obviously you get the same from jGrasp; I haven&aps;t used jGrasp for a long time.

JC: apart from the fact that I would have used a Scanner, too: Where are you initialising newphone? (That should read newPhoneNumber with capitalLetters.) Why have you posted code which won't compile?
In an earlier post you got the code tags wrong, but I corrected that for you.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I get one error:

ReadPhone.java:9: error: cannot find symbol
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
^
symbol: class InputStreamReader
location: class ReadPhone
1 error


 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh,

copy and pasting your exact code into my NetBeans IDE, and only changing the class name to "Junk" to match my existing forum project, I don't get that problem at all.

The only problem I get is an uncaught exception down where you have this:

and when I put it in a try/catch it works, but does give a rull error at the end of the run after outputting the formatted phone number.

BTW: how is that a pseudocode program, you are writing in Java?
 
Stephen M Davies
Greenhorn
Posts: 11
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised you don't mention another problem, where do you assign a value to the newPhone reference.?
In your code (which is not pseudo code) you initialize it with null, but don't assign it a value before trying to print it.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have already asked this question here; Don't ask the same question twice. I shall merge your two threads.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Castellanos wrote:I get one error:...

Josh, for future reference, when you copy an error message, copy it exactly as it appears, and enclose it in [code][/code] tags, because that preserves the spaces.
If I simply copy your message, you see:

ReadPhone.java:9: error: cannot find symbol
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
^

whereas WE want to see:

Note where the carat symbol is, which is vital to our understanding of the error.

HIH

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!