Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 BufferedReader error?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aziz




PostPosted: Sat Jun 25, 2005 7:56 pm   Post subject: BufferedReader error?

Why does this code:

code:
/* Class "ScheduleManager"
 * Includes methods to write and read work schedules
 * for McDonald's employee.
 */
 
 import java.util.*;
 import java.io.*;
 
 public class ScheduleManager
 {      
        //Vector to store strings of scheduled days
        Vector days = new Vector(0,1);
        
        //Method to get the schedule
        private void readSchedule () throws IOException
        {
               //Input object
               BufferedReader input;
               
               //Input line
               String line;
               
               //Declares input stream from
               input = new BufferedReader(new FileReader("schedule.dat"));
               
               while (true)
               {
                      line = input.readLine();
                      if (line == null) break;
                      days.add(line);
               }
               
               input.close();
        }
 }


give my this compile-time message:

code:
--------------------Configuration: <Default>--------------------
Note: C:\Documents and Settings\Anthony\My Documents\Java\Schedule Manager\ScheduleManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Process completed.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sat Jun 25, 2005 10:05 pm   Post subject: (No subject)

Let me clear up something first. In Java you need not declare an object and initialize it separately.

code:
BufferedReader input = new BufferedReader(
   new FileReader("schedule.dat"));


That works just fine and saves you a line of code.
1of42




PostPosted: Sun Jun 26, 2005 12:41 am   Post subject: (No subject)

I'm not 100% sure why it says that - maybe drawing to your attention unchecked exceptions that you are not explicitly dealing with (despite the throws clause)?

It compiles without warnings for me though, so I'd say you're fine to work with the code.
Aziz




PostPosted: Mon Jun 27, 2005 1:10 am   Post subject: (No subject)

Thanks a bunch. And yeah, in the HighScoreList class I've been working on today (converted from Turing, java makes it much better Smile) i've been doing it in one statement, and no warnings like that. But it did compile fine and everything so I was guessing it was a warning. But to be on the save side. Razz
Hikaru79




PostPosted: Sun Jul 17, 2005 10:04 pm   Post subject: (No subject)

Try doing what the error says. It says to try recompiling with the -Xlint:unchecked flag, so do so, and this is what you get:
code:

$ javac -Xlint:unchecked *.java
ScheduleManager.java:30: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
          days.add(line);
                  ^
1 warning

Basically, you're not checking for a certain exception in the vector's add(E) method. This one throws a bunch of unchecked exceptions so I'm not sure which one its complaining about, but ClassCastException is the most likely candidate. Try catching that and see what happens Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: