Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer Exception
    primarykey
    data
    text
    <p>I'm going nuts trying to figure this one out.When I click on my activity it crashes with a NullPointerException.I've tried debugging but I can't get into the activity in question.I've tried removing the Database,still crashed.I tried removing the ListView,still crashed.I tried modifying the database,still crashed.</p> <p>For some odd reason when I removed the button and its onClickListener on "playbutton",I was able to get into the activity and everything in the activity worked.Can someone help me on why this button is making the app crash before the activity and not on the onclick?</p> <pre><code>04-05 23:15:15.886: E/AndroidRuntime(11445): FATAL EXCEPTION: main 04-05 23:15:15.886: E/AndroidRuntime(11445): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fullfrontalgames.numberfighter/com.fullfrontalgames.numberfighter.PlayAFriend}: java.lang.NullPointerException 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread.access$700(ActivityThread.java:141) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.os.Handler.dispatchMessage(Handler.java:99) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.os.Looper.loop(Looper.java:137) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread.main(ActivityThread.java:5059) 04-05 23:15:15.886: E/AndroidRuntime(11445): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 23:15:15.886: E/AndroidRuntime(11445): at java.lang.reflect.Method.invoke(Method.java:511) 04-05 23:15:15.886: E/AndroidRuntime(11445): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792) 04-05 23:15:15.886: E/AndroidRuntime(11445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 04-05 23:15:15.886: E/AndroidRuntime(11445): at dalvik.system.NativeStart.main(Native Method) 04-05 23:15:15.886: E/AndroidRuntime(11445): Caused by: java.lang.NullPointerException 04-05 23:15:15.886: E/AndroidRuntime(11445): at com.fullfrontalgames.numberfighter.PlayAFriend.onCreate(PlayAFriend.java:54) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.Activity.performCreate(Activity.java:5058) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 04-05 23:15:15.886: E/AndroidRuntime(11445): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100) </code></pre> <p><strong>Activity</strong></p> <pre><code>package com.fullfrontalgames.numberfighter; import com.fullfrontalgames.numberfighter.DBAdapter; import com.fullfrontalgames.numberfighter.R; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.support.v4.widget.SimpleCursorAdapter; import android.view.View; import android.widget.Button; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; public class PlayAFriend extends Activity{ DBAdapter DBAdapter; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.playafriend); final DBAdapter db = new DBAdapter(this); DBAdapter = db.open(); ListView FriendLV = (ListView) findViewById(android.R.id.list); Button playbutton = (Button) findViewById(R.id.playbutton); final TextView friend = (TextView) findViewById(R.id.textview_friends); Cursor friendslist = db.GetAllFriends(); String[] from = new String[] {"FRIENDS"}; // your column/columns here int[] to = new int[] {R.id.textview_friends}; @SuppressWarnings("deprecation") ListAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.list_items, friendslist, from, to,0); FriendLV.setAdapter(cursorAdapter); playbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String Defender = friend.getText().toString(); db.GetFriend(Defender); startActivity(new Intent ("com.fullfrontalgames.numberfighter.Fightattacker")); db.close(); } }); } } </code></pre> <p>playafriend xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/nfbackground" android:orientation="vertical" &gt; &lt;ImageView android:id="@id/titlebar" android:layout_width="wrap_content" android:layout_height="66dp" android:src="@drawable/nftitlebar" /&gt; &lt;ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>list_items xml </p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:background="@drawable/searchimageview" android:orientation="vertical" &gt; &lt;Button android:id="@+id/playbutton" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="right" android:background="@drawable/playbutton" /&gt; &lt;TextView android:id="@+id/textview_friends" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textStyle="bold" android:textSize="40dp" android:layout_gravity="center" /&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload