este es el código
Código:
package com.example.usuario.calculadora; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements Button.OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { Button miboton; super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //7 miboton=(Button)findViewById(R.id.b7); miboton.setOnClickListener(this); //8 miboton=(Button)findViewById(R.id.b8); miboton.setOnClickListener(this); //9 miboton=(Button)findViewById(R.id.b9); miboton.setOnClickListener(this); //4,5 y 6 miboton=(Button)findViewById(R.id.b4); miboton.setOnClickListener(this); miboton=(Button)findViewById(R.id.b5); miboton.setOnClickListener(this); miboton=(Button)findViewById(R.id.b6); miboton.setOnClickListener(this); //1,2 y3 miboton=(Button)findViewById(R.id.b1); miboton.setOnClickListener(this); miboton=(Button)findViewById(R.id.b2); miboton.setOnClickListener(this); miboton=(Button)findViewById(R.id.b3); miboton.setOnClickListener(this); } public void teclaNumericaContorl(View v) { String textobotonpulsado , mensaje, resul; Button botonpulsado=(Button)v; textobotonpulsado=botonpulsado.getText().toString(); mensaje="has pulsado una tecla"+textobotonpulsado; Toast.makeText(this,mensaje,Toast.LENGTH_SHORT).show(); } public void onClick(View v) { teclaNumericaContorl(v); } }
la aplicacion me da un error y me sale un mensaje en inglés que me dice "se cerró la aplicacion inesperadamente" , nisiquiera ejecutandose, esta es la salida que me da el ide
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: FATAL EXCEPTION: main
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.usuario.calculadora/com.example.usuario.calculadora.MainActivity}: java.lang.NullPointerException
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2180)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2230)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThre ad.java:141)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1234)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99 )
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.jav a:5041)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:793)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:560)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: Caused by: java.lang.NullPointerException
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at com.example.usuario.calculadora.MainActivity.onCre ate(MainActivity.java:31)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5 104)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1080)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2144)
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2230)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThre ad.java:141)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1234)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99 )*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.jav a:5041)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:793)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:560)*
11-16 09:14:27.532 1163-1163/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)*
11-16 09:14:33.076 1163-1163/? I/Process: Sending signal. PID: 1163 SIG: 9
No se porqué nisiquiera me abre la app. Echadme una mano por favor.