Home > Mobile >  Null pointer exception android two-dimensional array
Null pointer exception android two-dimensional array

Time:10-02

In the process of the program runs a two dimensional array of null values
MainActivity. Pieces with normal value
MainActivity. Pieces [I] have normal values
MainActivity. Pieces [I] [j] is empty

Confusingly, MainActivity. Pieces [j] [I] is not less than the value, every time when debugging, can sometimes get to the correct value for the first time, but the second time certainly not

I=0, j=0

CodePudding user response:

When we have to have is that there is no,

Have an array or collection value depends on anyone to add value inside,

No one add value, of course, you did not take out, what's the problem?

Free pointer exception that is the reason why you didn't do judgment, you don't check the data length values directly, it may throw exceptions,

Check length before fetch the data from an array or collection is the basis of the Java programming operation, at the main good coding habits

CodePudding user response:

[I] [j] no assignment

CodePudding user response:

reference 1/f, dear Joe reply:
is there, no is no,

Have an array or collection value depends on anyone to add value inside,

No one add value, of course, you did not take out, what's the problem?

Free pointer exception that is the reason why you didn't do judgment, you don't check the data length values directly, it may throw exceptions,

Check length before fetch the data from an array or collection is the basis of the Java programming operation, looked at the topic main good coding habits


Have value, in the picture all array values can be displayed in the debug, [I] value is normal, but [I] [j] value is null, debugging is not always null, but the vast majority of null
This thing with grammar explanation is not clear, doubt is the problem that the underlying code
Really can't find the way, can only be rewritten again all the code

CodePudding user response:

You can look at the code

CodePudding user response:

reference swyxswyx reply: 3/f
Quote: reference 1/f, dear Joe reply:

When we have to have is that there is no,

Have an array or collection value depends on anyone to add value inside,

No one add value, of course, you did not take out, what's the problem?

Free pointer exception that is the reason why you didn't do judgment, you don't check the data length values directly, it may throw exceptions,

Check length before fetch the data from an array or collection is the basis of the Java programming operation, looked at the topic main good coding habits


Have value, in the picture all array values can be displayed in the debug, [I] value is normal, but [I] [j] value is null, debugging is not always null, but the vast majority of null
This thing with grammar explanation is not clear, doubt is the problem that the underlying code
Really can't find the way, can only be rewritten again all the code

If you don't rush to doubt the underlying code, even such a simple requirements are fulfilled, the Java language also have no necessary to continue to exist,

I can only say to here, the information you provide is not much, I also not good to analyze problems you remove the cause of null the two-dimensional array,

If continue to analyze, you need to describe what you have to do, and then take a look at your log,

The underlying no problem

CodePudding user response:

Pieces for you to create their own, isn't it? Where to modify their find, I, j is how to traverse, MAO didn't say we will count?

By the way, ask you a question: NullPintException, a great god is me, to save me,

CodePudding user response:

Pull down, write a two dimensional array is the underlying problem, a bit funny, your code to look at, what is the problem
  • Related