Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is the app crashing?
    text
    copied!<p>I am a new programmer to android. I have checked my code over and over again but just cant make out to get it running!!</p> <pre><code>public class Playlist extends Activity { Cursor cursor; @Override protected void onCreate(Bundle savedInstanceState) { ListView myListView = (ListView)findViewById(R.string.playlistHolder); final ArrayList&lt;String&gt; songslist= new ArrayList&lt;String&gt;(); final ArrayAdapter&lt;String&gt; aa= new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,songslist); myListView.setAdapter(aa); /*requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);*/; setContentView(R.layout.activity_playlist); // Show the Up button in the action bar. setupActionBar(); String[] STAR = { "*" }; Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; cursor = managedQuery(allsongsuri, STAR, selection, null, null); if (cursor != null) { if (cursor.moveToFirst()) { do { //SongName String song_name = cursor .getString(cursor .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); //SongID int song_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media._ID)); //SongPath String fullpath = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.DATA)); //Song's album name String album_name = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.ALBUM)); //Song's album ID int album_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); //Song's artist name String artist_name = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.ARTIST)); //Song's artist ID int artist_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID)); songslist.add(song_id,song_name);//Adding Song to Arraylist aa.notifyDataSetChanged();//Notifying Listview about addition of song. } while (cursor.moveToNext()); } cursor.close(); } super.onCreate(savedInstanceState); } /** * Set up the {@link android.app.ActionBar}, if the API is available. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupActionBar() { if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.playlist, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } </code></pre> <p>The application crashes as soon as I click on the Playlist button! I have initiated a new Intent from my home activity ->Playlist It is as follows</p> <pre><code>playlist.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent plist = new Intent(arg0.getContext(), Playlist.class); startActivityForResult(plist, 0); } }); </code></pre>
 

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