Excepción de puntero nulo al iniciar una nueva actividad
Bueno, estoy recibiendo una excepción de puntero nulo cuando empiezo mi tercera actividad. Aquí está el mensaje LogCat:
12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): java.lang.RuntimeException: No se puede iniciar la actividad ComponentInfo {com.acithium.main / com.acithium.rss.ShowDescription}: java.lang.NullPointerException 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2401) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2417) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread.access $ 2100 (ActivityThread.java:116) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1794) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.os.Handler.dispatchMessage (Handler.java:99) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.os.Looper.loop (Looper.java:123) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread.main (ActivityThread.java:4203) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en java.lang.reflect.Method.invokeNative (Método nativo) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en java.lang.reflect.Method.invoke (Method.java:521) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:791) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en com.android.internal.os.ZygoteInit.main (ZygoteInit.java:549) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en dalvik.system.NativeStart.main (Método nativo) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): Causado por: java.lang.NullPointerException 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en com.acithium.rss.ShowDescription.onCreate (ShowDescription.java:48) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1123) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): en android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2364) 12-28 04: 38: 00.350: ERROR / AndroidRuntime (776): ... 11 más
Aquí está la sección del código donde llamo la actividad:
- Se produjo un error interno durante: "Actualización de la biblioteca de Android". java.lang.NullPointerException
- La aplicación se bloquea al intentar establecer una conexión VPN?
- Android: NullPointerException en android.app.ActivityThread $ PackageInfo $ ServiceDispatcher.doConnected (ActivityThread.java:1012)
- Android SDK Content Loader falla con NullPointerException
- NPE mientras infla el diseño (Intentar invocar el método virtual 'boolean java.lang.String.equals (java.lang.Object)' en una referencia de objeto nulo)
public void onItemClick(AdapterView parent, View v, int position, long id) { Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]"); Intent itemintent = new Intent(this,com.acithium.rss.ShowDescription.class); //Intent itemintent = new Intent(); //itemintent.setClassName("com.acithium.main", "com.acithium.rss.ShowDescription"); Bundle b = new Bundle(); b.putString("title", feed.getItem(position).getTitle()); b.putString("description", feed.getItem(position).getDescription()); b.putString("link", feed.getItem(position).getLink()); itemintent.putExtra("android.intent.extra.INTENT", b); startActivityForResult(itemintent,0); }
Y aquí está la nueva clase de actividad que se llama:
public class ShowDescription extends Activity { public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.showdescription); String theStory = null; Intent startingIntent = getIntent(); if (startingIntent != null) { Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT"); if (b == null) { theStory = "bad bundle?"; } else { theStory = b.getString("title") + "\n\n" + b.getString("description") + "\n\nMore information:\n" + b.getString("link"); } } else { theStory = "Information Not Found."; } TextView db= (TextView) findViewById(R.id.storybox); db.setText(theStory); Button backbutton = (Button) findViewById(R.id.back); backbutton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { finish(); } }); } }
Aquí está el archivo showdescription.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoLink="all" android:text="story goes here ...." android:id="@+id/storybox" /> <Button android:layout_height="wrap_content" android:text="Back" android:id="@+id/back" android:layout_width="100px" android:layout_marginLeft="100px"/> </LinearLayout> </ScrollView> </LinearLayout>
- MapView - Android
- Captura de fotos La intención causa NullPointerException en los teléfonos Samsung solamente
- Mi ubicación actual siempre devuelve null. ¿Cómo puedo arreglar esto?
- NullPointerException en rotación durante el comando dispatchCreateOptionsMenu, la traza de pila no incluye ninguna función en mi aplicación
- Android ActivityOptions.isReturning () NullPointerException
- No se puede iniciar el servicio con null
- Class.getResource (className) que me da NullPointerException
- Intenta invocar el método virtual 'int android.text.Layout.getLineCount ()' en una referencia de objeto nulo
Esta es tu pista, desde el seguimiento de la pila:
12-28 03:47:21.670: ERROR/AndroidRuntime(862): Caused by: java.lang.NullPointerException 12-28 03:47:21.670: ERROR/AndroidRuntime(862): at com.acithium.rss.ShowDescription.onCreate(ShowDescription.java:47)
¿Qué es la línea 47 en ShowDescription.java?
Si he entendido bien el código, debería invocar el findViewById () de la vista showdescription que estableció para la actividad y no de la actividad, ya que ambos, button y textview, parecen ser parte de esa vista:
super.onCreate(icicle); View showdescription = this.findViewById(R.id.showdescription); setContentView(showdescription); // .. TextView db = (TextView)showdescription.findViewById(R.id.storybox); db.setText(theStory); Button backbutton = (Button)showdescription.findViewById(R.id.back); backbutton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { finish(); } });
¿Cuál es la línea 47 en tu código ShowDescription? Creo que está pasando un cursor nulo.