Results 1 to 2 of 2
  1. #1
    lenjaku is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default 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);	
    		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)
    		description=new String(roomDescription);

    here is my code:

    Java Code:
    static Hotel LoadHotelFromFile(String file_name) throws Exception
    		  { // Create a File instance
  file = new;
    			    // Create a Scanner for the file
    			    Scanner input = new Scanner(file);
    			    // Read data from a file			   
    			   String hotel_line =;
    		      Hotel hotel=hotel_extractor(hotel_line);
    			   while (input.hasNext()) // blank is the token 
    			       Room r=room_extractor(room_line);
    			       if (!hotel.AddRoom(r))
    						System.out.println("error adding room");
    			    // Close the file
    			    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;
    This is simply loading from a file, first line should create an object of the type Hotel which contains an array of type Room.

    I don't get why it won't create it

    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(
    at Program.LoadHotelFromFile(
    at Program.main("

    Apparently this line bugs it:
    Java Code:
    Scanner input = new Scanner(file);
    Last edited by lenjaku; 01-18-2013 at 09:02 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: error msg : "source not found"

    Quote Originally Posted by lenjaku View Post
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at Program.room_extractor(
    at Program.LoadHotelFromFile(
    at Program.main("

    Apparently this line bugs it:
    " Scanner input = new Scanner(file);"
    The stack trace shows that the exception arose from line 148 in the room_extractor method of There's no " Scanner input = new Scanner(file);" in that method.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. "source not found" error in Eclipse
    By MCinPgh in forum New To Java
    Replies: 1
    Last Post: 01-16-2013, 04:27 PM
  2. Replies: 0
    Last Post: 02-02-2012, 08:24 AM
  3. debugger "Source not found"
    By j2me64 in forum Eclipse
    Replies: 2
    Last Post: 03-30-2010, 10:22 AM
  4. Replies: 0
    Last Post: 11-22-2008, 02:49 AM
  5. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 07:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts