Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

swing - How to solve java.lang.ArrayIndexOutOfBoundsException: 1 in Java jframe?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let me try to guide you debugging the issue. The exception should give you the line number at which the exception is thrown. ArrayIndexOutOfBoundsException is thrown when you try to access array with an index that is not available in the array. Given that the error is about index 1, then the error seems to be either at line

array[counter].setSubjectName(inputArray[1]);

or

array[counter] = new Obligations();   

after the counter is incremented. Most probably it is the first one, the stack trace should confirm it

Next step of debugging is to figure out the value of the array before the errorneous line. You can print out the value and see whether it is expected value or something else. Alternatively you can debug step-by-step in IDE

If it is not the expected value, backtrack to see how the variable value is calculated.

There are multiple things missing in the question due to which exact answer cannot be provided

  • array variable definition
  • inputArray variable definition
  • use of arrayInside variable
  • Line at which the exception is thrown

(Hint: "/t" is not tab )


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...