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 6194171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:15:00+00:00 2026-05-24T03:15:00+00:00

Exception in thread main java.lang.ArrayIndexOutOfBoundsException: -1 i have an array of boolean type which

  • 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

i have an array of boolean type
which is

static boolean[][] a = new boolean[50][50];

everytime gets input,
it marks the specified array as true
that is,

for(int i=0; i<k; i++){
  int x=sc.nextInt();
  int y=sc.nextInt();
  a[x][y] = true;
}

but when the number of input, depending on k, gets large,
the following error comes out

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

what is wrong with this

  • 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-05-24T03:15:01+00:00Added an answer on May 24, 2026 at 3:15 am

    The Exception you see is because you’re trying to access an element of the array that doesn’t exist (Lies Outside the Bounds).

    The array you initialize has elements 0…49 in both dimensions. So you can insert values into any position that lies within a[0-49][0-49]

    When you do:

    int x=sc.nextInt();
    int y=sc.nextInt();
    a[x][y] = true; 
    

    There’s the possibliity that you access a value beyond those locations. Such as a negative value or a too high one (In this case you’re accessing -1).

    Your issue stems from the fact that sc.nextInt() is failing to produce a usable integer from your input. How are you initializing sc?

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

Sidebar

Related Questions

Seem to have a problem starting my Java app: Exception in thread main java.lang.NoClassDefFoundError:
the program gives following exception: Exception in thread main java.lang.NullPointerException at myclasses.BubbleSort.run(BubbleSort.java:42) at acm.program.Program.runHook(Program.java:1519)
I am getting this error: Exception in thread main java.lang.OutOfMemoryError: Java heap space at
Why does I get an exception Exception in thread main java.lang.ClassCastException: [Ljava.lang.Object; cannot be
I'm getting the error Exception in thread main java.lang.NumberFormatException: For input string: scores.txt at
Exception in thread main java.lang.IllegalArgumentException: Fetcher: No agents listed in 'http.agent.name' property. at org.apache.nutch.fetcher.Fetcher.checkConfiguration(Fetcher.java:1166)
I'm getting the error: Exception in thread main java.lang.NullPointerException at com.deanchester.minos.utils.DatabaseManager.createTables(DatabaseManager.java:59) at com.deanchester.minos.tests.testAddContestantMethod.main(testAddContestantMethod.java:21) I
Exception in thread main java.lang.ClassCastException: org.apache.derby.client.am.Statement cannot be cast to java.beans.Statement at CollegeLibrary.NotRegistered.DBStatement(NotRegistered.java:114) at
I am getting something like the following: Exception in thread main java.lang.UnsatisfiedLinkError: no viewerNativeDLL
java -Djava.library.path=. TestJNI >>>> Exception in thread main java.lang.UnsatisfiedLinkError: TestJNI.calibrate([D[DII)[D at TestJNI.calibrate(Native Method) 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.