Jason

name == null

would not cause NPE, as it is simple assignment to a member variable
in MyPlayer class. If there was anything else within setName() that
caused NPE, we could see it on the top of the stacktrace.

The cause is that *player* reference in *player_input.setName()* is null.

The way player object is being constructed is wrong: (player = new
Player;)  This code should not compile, so it begs the question, how
did the OP manage to run it.

There are many other issues with this code from the first look, like
naming conventions, and auto generated comments dotting it, just to
name the few.



Daniel




On 23 May 2012 10:56, Jason Teagle <[email protected]> wrote:
>> I've create an object class but it cannot work. any mistake of my code?
>
>
>> private void setName() {
>> // TODO Auto-generated method stub
>> getNameText();
>> for (int i=0; i<NUM_PLAYER; i++){
>> player.setPlayerName(name); // name is a String get from EditText by some
>> code before
>> }
>> }
>
>
>> when I run the programme, it have the following error code:
>
>
>> 05-23 09:24:35.115: E/AndroidRuntime(438): java.lang.NullPointerException
>> 05-23 09:24:35.115: E/AndroidRuntime(438):  at hktsang56.android.mjhelper
>> .name_input.setName(name_input.java:81)
>
>
> Which of the lines in your source code is line 81? Is it the line that says
> getNameText()? We need to see that method's definition, if that is the case,
> since I can't see any other problem (if 'name' were coming out null, then
> the error would be in setPlayerName() rather than in setName() - in fact it
> probably wouldn't generate an error in such a case).
>
> Show us the code for getNameText(). You are possibly trying to access a
> control that you have not filled out correctly.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to