cantmano is the index, it starts on 0. Another method increases with cant++. I recheck that 0 <= cantmano <= 10
public void dibujar(){
//actualiza la pantalla
if (cantmano >= 0 && cantmano < 10 && cantcroupier >= 0 && cantcroupier < 10){
TextView textomano = (TextView)findViewById(R.id.textView3);
TextView textocroupier = (TextView)findViewById(R.id.textView5);
CharSequence buffer = textomano.getText();
textomano.setText( buffer + " " +
String.valueOf(manojugador[cantmano].getPalo())+ " de " +
String.valueOf(manojugador[cantmano].getNumero()) ); // <-- ERROR
textocroupier.setText( String.valueOf(cantmano) );
}
}
I get a nice
Caused by: java.lang.NullPointerException at com.pruebas.blackjack.blackjack.dibujar(blackjack.java:58) at com.pruebas.blackjack.blackjack.onCreate(blackjack.java:23) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
EDITS:
.getNumero()
returns the int with the value of a requested CARD. (playing card type)
.getPalo()
returns an int where 1= diamonds, etc.
initialization of manojugador:
Carta manojugador[]= new Carta[10];
constructor of Carta:
public Carta(){
int palo=0;
int numero=0;
}
MIDNIGHT UPDATE: With some improvements i managed it to get over the error. BUT now the array has all 0 values when written. This has to be an easy to solve but that's the final step before accepting the best answer.
Here's the method that adds cards:
public void hit(View v){
//sacan cartas
if (cantmano < manojugador.length){
manojugador[cantmano]=mazo.darcarta(); //adds a random Card to the manojugador. mazo means deck.
manocroupier[cantcroupier]=mazo.darcarta(); //adds a random Card to the manojugador. mazo means deck.
cantmano++;
cantcroupier++;
}
dibujar();
}
com.pruebas.blackjack.blackjack.dibujar(blackjack.java:58)
manojugador
array. I suspect it's not being initialized completely.NullPointerException
is thrown with the// <-- ERROR
comment.