0

when I select my btnPlaylist in my main.java I get the error code at the botton. I dont know what I'm doing wrong. It's saying I need to have a ListView with the R.id.list. I'm assuming it referring to my playlist_item_row.xml but I tried that and keep cleaning my project.

public class PlayListActivity extends ListActivity {
ListView listView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playlist);

   listView = (ListView)findViewById(R.id.listView);
    //double check that it's list_item

    String[] songs = this.getResources().getStringArray(R.array.TrackNames);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.playlist_item_row,R.id.song_title,songs);

    listView.setAdapter(adapter);
}

} this is the xml for PlayListActivity.java called playlist.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="#242424"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_selector" />

This xml I have holding my values resources xml in res>values>'track_array.xml'

      <resources>
    <string-array name="TrackNames">
        <item>100 - Welcome to London</item>
        <item>102 - Trafalgarsquare</item>
</string-array>
</resources>

playlist_item_row.xml

<TextView
    android:id="@+id/song_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:padding="10dp" />

main.java

 private MediaPlayer mp;
private MediaPlayer nextMp;
private TextView tvTime;
private long currentTime;
private long duration;
private boolean isPlaying;

private boolean mCompatMode = true;
private MediaPlayer mNextPlayer;
private OnCompletionListener mCompletion;

private ImageButton btnPlay;
private ImageButton btnPlaylist;
private SeekBar songProgressBar;
private TextView songTitleLabel;
//private Handler mHandler = new Handler(); // Handler to update UI timer, progress bar etc,.
//private SongsManager songManager;
private Utilities utils;
private String[] fileList;
//private int seekForwardTime = 5000; // 5000 milliseconds
//private int seekBackwardTime = 5000; // 5000 milliseconds
//private int currentSongIndex = 0;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.player);

    // All player buttons
    btnPlay = (ImageButton) findViewById(R.id.btnPlay);
    btnNext = (ImageButton) findViewById(R.id.btnNext);
    btnBack = (ImageButton) findViewById(R.id.btnBack);
    btnPlaylist = (ImageButton) findViewById(R.id.btnPlaylist);
    songProgressBar = (SeekBar) findViewById(R.id.songProgressBar);
    songTitleLabel = (TextView) findViewById(R.id.songTitle);
   // PlayListActivity():

    fillAssetList();
    Toast.makeText(getApplicationContext(), "fill asset list", Toast.LENGTH_LONG).show();

    if (savedInstanceState != null) {
        duration = savedInstanceState.getLong("duration");
        currentTime = savedInstanceState.getLong("currentTime");
        isPlaying = savedInstanceState.getBoolean("isPlaying");

        if (isPlaying) {
            pauseMusic(null);
        }

    }

    btnPlaylist.setOnClickListener(new View.OnClickListener() {

        //@Override
        public void onClick(View arg0) {
            Intent i = new Intent(getApplicationContext(), PlayListActivity.class);
            startActivityForResult(i, 100);
        }
    });



}

main_layout.xml

<!-- Playlist button -->
    <ImageButton 
        android:id="@+id/btnPlaylist"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/btn_playlist"
        android:background="@null"/>
</LinearLayout>

error

    03-08 06:16:14.149  25914-25914/com.macmac.tourplayer W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41854e90)
03-08 06:16:14.159  25914-25914/com.macmac.tourplayer E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.macmac.tourplayer, PID: 25914
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.macmac.tourplayer/com.macmac.tourplayer.PlayListActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
            at android.app.ActivityThread.access$800(ActivityThread.java:142)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5118)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ListActivity.onContentChanged(ListActivity.java:243)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:322)
            at android.app.Activity.setContentView(Activity.java:1973)
            at com.macmac.tourplayer.PlayListActivity.onCreate(PlayListActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:5275)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
            at android.app.ActivityThread.access$800(ActivityThread.java:142)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5118)
            at java.lang.reflect.Method.invokeNative(Native Method)
garrettmac
  • 8,417
  • 3
  • 41
  • 60
  • have you tried changing `android:id="@+id/listView"` to `android:id="@+id/list"`? – DevJem Mar 08 '15 at 12:42
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Simon Mar 08 '15 at 12:58

3 Answers3

1

Change the id of listview in playlist.xml

android:id="@android:id/list"
Simar
  • 600
  • 4
  • 17
  • Why should he change? – Apurva Mar 08 '15 at 12:47
  • Since he is using a ListActivity and not a regular activity, the layout shoulf contain a list with that particular id. Either he needs to change the id or stop using ListActivity. – Simar Mar 08 '15 at 12:48
0

Checked reference on ListView. The setAdapter takes a ListAdapter instead of your ArrayAdapter. setAdapter(ListAdapter adapter)

DevJem
  • 656
  • 1
  • 13
  • 21
0

ok, I figured it out. I had to extend Activity and not ListActivity. I don't really understand why but it worked.

garrettmac
  • 8,417
  • 3
  • 41
  • 60