Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:50:12+00:00 2026-06-12T18:50:12+00:00

I am trying to create a map in the shape of grid 4 columns

  • 0

I am trying to create a map in the shape of grid 4 columns X 5 Rows and connect each rooms together. Below code compiles but when I try to run it it comes up with the error. Could anyone please tell me where its gone wrong? Thanks.

  public static final int NUM_ROOMS = 20; 

  public static final int NUM_COLS = 4; 

  private ArrayList<Room> myRooms;

  public Map(){

     int row =0;
     ArrayList<Room> myRooms = new ArrayList<Room>();
     while (row<NUM_COLS){
        int i =0;
        i = row % NUM_COLS;
        while(i+1<NUM_COLS){
           while (i+1 <(row+1)% NUM_COLS){
              Room r1 = myRooms.get(i);
              Room r2 = myRooms.get(i+1);
              r1.connectTo(r2);
              r2.connectTo(r1);
              i++;
           }
           row++;
        }

        int col = 0;

        while (col<NUM_COLS){
           i = col; 
           while (i+4<NUM_ROOMS){
             i = i+NUM_COLS; 
            }
            col++;
        }

     }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:50:13+00:00Added an answer on June 12, 2026 at 6:50 pm

    The issue is that the myRooms list is empty. So when you try to get an element out of the list, you get an exception. You have to use something like

    for (int i = 0; i < NUM_ROOMS; i++) {
        myRooms.add(new Room());
    }
    

    to populate the list first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a map with 3 different markers, but currently each
I am trying to create a map by taking the first character of each
i've been trying to create a map-related android app, but i realized that the
I'm trying to dynamically create a map collection but I am still new to
I am trying to create a map using two arrays. Here is the code:
I'm trying to create a map of function names and function pointers using __stdcall.
I'm trying to create a map, where the key is an int , and
I am trying to create an interactive map where users can click on different
I'm trying to create a mutable Map with a default that creates a new
I'm trying to create an inverted index in a map from a map .At

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.