Hola buenas, estoy haciendo una aplicacion sencilla de 20 preguntas y me da error al final cuando trato de mostrar el resultado.
"Unfortunately, My aplication has stopped.
package com.example.nayime.aplicacionfinal;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Resultadofinal extends ActionBarActivity {
private int acumulador;
private TextView respuestaresultado;
private Button reiniciar;
@
override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resultadofinal);
Bundle bundle = this.getIntent().getExtras();
acumulador = bundle.getInt("acumulador");
respuestaresultado = (TextView) findViewById(R.id.resultadofinal);
respuestaresultado.setText("Tu puntuación final obtenida ha sido de "+acumulador+" puntos. Felicidades.");
reiniciar.setOnClickListener(new View.OnClickListener() {
@
override
public void onClick(View v) {
Intent intentreinicio =
new Intent(Resultadofinal.this, primeratandapreguntas.class);
int control = 1;
int acumulador = 0;
Bundle i = new Bundle();
i.putInt("acumulador", acumulador);
i.putInt("control",control);
intentreinicio.putExtras(i);
startActivity(intentreinicio);
}
});
}
}
Aqui el codigo del activity, esta formado por un textview que no le puse texto en el xml, un imageview despues y por ultimo un boton.
No se por donde estara el fallo, porque he usado esto parecido, imagino que va por el textview el fallo creo quizas deba convertir a String la variable acumulador aunque en otra ocasion si me ha funcionado de la forma que lo muestro.
El error que me sale en el log es:
03-02 10:10:52.373 640-640/com.example.nayime.aplicacionfinal E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nayime.aplicacionfinal/com.example.nayime.aplicacionfinal.Resultadofinal} : java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThre ad.java:123)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.nayime.aplicacionfinal.Resultadofinal. onCreate(Resultadofinal.java:31)
at android.app.Activity.performCreate(Activity.java:4 465)
at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:1920)
************at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1981)
************at android.app.ActivityThread.access$600(ActivityThre ad.java:123)
************at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1147)
************at android.os.Handler.dispatchMessage(Handler.java:99 )
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.jav a:4424)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:511)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:784)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:551)
************at dalvik.system.NativeStart.main(Native Method)
Sorry si me pase de tocho pegando informacion aqui directamente.