Results 1 to 2 of 2
Thread: error msg : "source not found"
- 01-18-2013, 07:13 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 1
- Rep Power
- 0
error msg : "source not found"
Well I got this msg before when my array was out of bounds but now it won;t even let me create an object so I am puzzled.
These are my objects (Hotel and Room)
Java Code:public class Hotel { private String hotel_name; private Room[] hotel; private int num_of_rooms; public Hotel(String hotelName,int maxNumOfrooms) { hotel_name=new String(hotelName); num_of_rooms=0; hotel=new Room[maxNumOfrooms]; }
Java Code:public class Room { private int room_number; private int num_of_beds; private String description; public Room(int roomNum,int numOfBeds,String roomDescription) { room_number=roomNum; num_of_beds=numOfBeds; description=new String(roomDescription); }
here is my code:
This is simply loading from a file, first line should create an object of the type Hotel which contains an array of type Room.Java Code:static Hotel LoadHotelFromFile(String file_name) throws Exception { { // Create a File instance java.io.File file = new java.io.File(file_name); // Create a Scanner for the file Scanner input = new Scanner(file); // Read data from a file String hotel_line = input.next(); Hotel hotel=hotel_extractor(hotel_line); while (input.hasNext()) // blank is the token { String room_line=input.next(); Room r=room_extractor(room_line); if (!hotel.AddRoom(r)) System.out.println("error adding room"); } // Close the file input.close(); return hotel; } } static private Hotel hotel_extractor(String hotel_line) { String[] hotelinfo=hotel_line.split("[%@]"); String hotel_name=hotelinfo[0]; int max_number_of_rooms=Integer.parseInt(hotelinfo[2]); Hotel hotel=new Hotel(hotel_name,max_number_of_rooms); return hotel; } static private Room room_extractor(String room_line) { int i=0; String[] roominfo=room_line.split("[#]"); String roomdesc=roominfo[i++]; int room_number=Integer.parseInt(roominfo[i++]); int number_of_beds=Integer.parseInt(roominfo[i++]); Room room=new Room(room_number,number_of_beds,roomdesc); return room; }
I don't get why it won't create it.gif)
ps: I checked the variables after the split, each contains what it should whether it;s a string or int...
while I run it regularly (not in debug mode) it says array out of bounds
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Program.room_extractor(Program.java:148)
at Program.LoadHotelFromFile(Program.java:120)
at Program.main(Program.java:40)"
Apparently this line bugs it:
Java Code:Scanner input = new Scanner(file);
Last edited by lenjaku; 01-18-2013 at 08:02 AM.
- 01-18-2013, 08:03 AM #2
Re: error msg : "source not found"
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
"source not found" error in Eclipse
By MCinPgh in forum New To JavaReplies: 1Last Post: 01-16-2013, 03:27 PM -
Applet error "Fish.class not found" while running through Chrome.
By DaveAp7 in forum New To JavaReplies: 0Last Post: 02-02-2012, 07:24 AM -
debugger "Source not found"
By j2me64 in forum EclipseReplies: 2Last Post: 03-30-2010, 10:22 AM -
"source not found" at debug time when creating new class
By rafamd11 in forum New To JavaReplies: 0Last Post: 11-22-2008, 01:49 AM -
Strange error message "Source not found"
By ppayal in forum EclipseReplies: 0Last Post: 11-25-2007, 06:19 PM


LinkBack URL
About LinkBacks


Bookmarks