Hi, I have been trying to get this to compile, and it will not. How come? It keeps telling me something is wrong with my readLine. Ugh. package java192.project5; import java.io.*; import java.util.*; public class SendPackage { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); { System.out.println("Please enter the weight, shipping method - A, T or M - " + "and type the word 'insured' if insurance is desired."); System.out.println("Each item needs to be entered on ONE line followed " + "by a space."); int tokenCnt; int t = 0; String strInput = br.readLine(); StringTokenizer st = new StringTokenizer(strInput); tokenCnt = st.countTokens(); String[] strTokenArray = new String[tokenCnt]; if (st.hasMoreTokens()) { strTokenArray[t] = st.nextToken(); ++t; } } } Thx. CB
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Something is wrong? Why not tell us what exactly is wrong instead of making us copy your code and compile it? Here is the actual error: SendPackage.java:16: unreported exception java.io.IOException; must be caught or declared to be thrown String strInput = br.readLine(); ^ 1 error
So what is the problem? The error says that the readLine() might throw an IOException which must be caught! So catch it!
[ November 24, 2002: Message edited by: Thomas Paul ]
SendPackage.java:16: unreported exception java.io.IOException; must be caught or declared to be thrown String strInput = br.readLine(); ^ 1 error
You can either catch it as Thomas said, or you can declare it to be thrown.
For example: public static void main( String[] args ) throws IOException
Also, formatting your code makes it easier to read.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Clarabelle Smith
Greenhorn
Joined: Sep 17, 2002
Posts: 5
posted
0
Thank you BOTH for your help. I didn't notice when I pasted my code into here, it took away the formatting. I will make sure to add that back in for any future posts I may make. CB
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Note that to help preserve formatting, surround posted code with the [code] and [/code] UBB tags.