Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to start activity ComponentInfo{..} : java.lang.NullPointerException
    primarykey
    data
    text
    <p>I'm trying to start a new activity when the Button playlistBtn is clicked, and I'm getting a NullPointerException, but I can't see where did I go wrong with my references.</p> <p>Complete error log:</p> <pre><code>04-08 17:02:07.847: E/AndroidRuntime(5869): FATAL EXCEPTION: main 04-08 17:02:07.847: E/AndroidRuntime(5869): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.and.androidmusic/app.and.androidmusic.PlaylistActivity}: java.lang.NullPointerException 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread.access$600(ActivityThread.java:141) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.os.Handler.dispatchMessage(Handler.java:99) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.os.Looper.loop(Looper.java:137) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread.main(ActivityThread.java:5039) 04-08 17:02:07.847: E/AndroidRuntime(5869): at java.lang.reflect.Method.invokeNative(Native Method) 04-08 17:02:07.847: E/AndroidRuntime(5869): at java.lang.reflect.Method.invoke(Method.java:511) 04-08 17:02:07.847: E/AndroidRuntime(5869): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-08 17:02:07.847: E/AndroidRuntime(5869): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-08 17:02:07.847: E/AndroidRuntime(5869): at dalvik.system.NativeStart.main(Native Method) 04-08 17:02:07.847: E/AndroidRuntime(5869): Caused by: java.lang.NullPointerException 04-08 17:02:07.847: E/AndroidRuntime(5869): at app.and.androidmusic.PlaylistActivity.onCreate(PlaylistActivity.java:68) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.Activity.performCreate(Activity.java:5104) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 04-08 17:02:07.847: E/AndroidRuntime(5869): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) </code></pre> <p>MainActivity.java:</p> <pre><code> public class MainActivity extends ListActivity { ... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... Button btnPlaylist = (Button) findViewById(R.id.playlistBtn); btnPlaylist.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent in = new Intent(getApplicationContext(), PlaylistActivity.class); startActivity(in); </code></pre> <p>PlaylistActivity.java:</p> <pre><code>public class PlaylistActivity extends ListActivity{ ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_playlist); { </code></pre> <p>AndroidManifest.xml:</p> <pre><code>&lt;activity android:name="app.and.androidmusic.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".PlaylistActivity" /&gt; </code></pre> <p>Ok, so here is activity_main.xml as you asked it's quite long:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;app.and.androidmusic.DragNDropListView android:id="@+id/android:list" android:layout_width="match_parent" android:layout_height="300dp" android:layout_below="@+id/playlistBtn" android:layout_alignParentLeft="true" &gt; &lt;/app.and.androidmusic.DragNDropListView&gt; &lt;Button android:id="@+id/playBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/android:list" android:layout_toRightOf="@+id/prevBtn" android:text="@string/playBtn" /&gt; &lt;Button android:id="@+id/pauseBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/android:list" android:layout_toRightOf="@+id/playBtn" android:text="@string/pauseBtn" /&gt; &lt;Button android:id="@+id/prevBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/android:list" android:text="@string/prevBtn" /&gt; &lt;Button android:id="@+id/nextBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/android:list" android:layout_toRightOf="@+id/pauseBtn" android:text="@string/nextBtn" /&gt; &lt;Button android:id="@+id/songsBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/songTxt" android:text="@string/songsBtn" /&gt; &lt;Button android:id="@+id/playlistBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/songTxt" android:layout_toRightOf="@+id/songsBtn" android:text="@string/playlistBtn" /&gt; &lt;Button android:id="@+id/eqBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/songTxt" android:layout_toRightOf="@+id/playlistBtn" android:text="@string/eqBtn" /&gt; &lt;TextView android:id="@+id/songTxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="" /&gt; &lt;/RelativeLayout&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.
    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