Note that there are some explanatory texts on larger screens.

plurals
  1. POlistview with bug
    primarykey
    data
    text
    <p>I'm developing soundplayer app and when to run it on emulater it works but it does not work on physical device. The error when to click icon to start, I got an error and abended. Could someone take a look this code? here is the code.</p> <p>SoundPlayList Activity@</p> <pre><code>public class SoundPlayList extends Activity { public final static int PLAY_MUSIC = 0; private ListView mListView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.soundplayerlist); mListView = (ListView)findViewById(R.id.listView1); SoundPlayerAdapter adapter = new SoundPlayerAdapter(this); mListView.setAdapter(adapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent,View view,int position,long id){ ListView listView = (ListView)parent; String item = (String)listView.getItemAtPosition(position); Intent intent = new Intent(SoundPlayList.this, SoundPlayerActivity.class); intent.putExtra("id",parent.getItemIdAtPosition(position)); intent.putExtra("name",item); startActivityForResult(intent,PLAY_MUSIC); } }); } </code></pre> <p>SoundPlayerAdapter@</p> <pre><code>public class SoundPlayerAdapter extends ArrayAdapter&lt;String&gt;{ private ArrayList&lt;Long&gt; mMusicIds = new ArrayList&lt;Long&gt;(); public SoundPlayerAdapter(Context context) { super(context, android.R.layout.simple_list_item_1); ContentResolver resolver = context.getContentResolver(); Cursor cursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null,null,null,null); while(cursor.moveToNext()){ String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); mMusicIds.add(id); this.add(name); } } public long getItemId(int position){ return mMusicIds.get(position); } } } </code></pre> <p>log trace@</p> <pre><code>11-12 15:45:04.985: D/AndroidRuntime(5288): Shutting down VM 11-12 15:45:04.985: W/dalvikvm(5288): threadid=1: thread exiting with uncaught exception (group=0x2aac8578) 11-12 15:45:04.985: E/AndroidRuntime(5288): FATAL EXCEPTION: main 11-12 15:45:04.985: E/AndroidRuntime(5288): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.soundplayer/com.example.soundplayer.SoundPlayList}: java.lang.NullPointerException 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.os.Handler.dispatchMessage(Handler.java:99) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.os.Looper.loop(Looper.java:130) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread.main(ActivityThread.java:3701) 11-12 15:45:04.985: E/AndroidRuntime(5288): at java.lang.reflect.Method.invokeNative(Native Method) 11-12 15:45:04.985: E/AndroidRuntime(5288): at java.lang.reflect.Method.invoke(Method.java:507) 11-12 15:45:04.985: E/AndroidRuntime(5288): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 11-12 15:45:04.985: E/AndroidRuntime(5288): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 11-12 15:45:04.985: E/AndroidRuntime(5288): at dalvik.system.NativeStart.main(Native Method) 11-12 15:45:04.985: E/AndroidRuntime(5288): Caused by: java.lang.NullPointerException 11-12 15:45:04.985: E/AndroidRuntime(5288): at com.example.soundplayer.SoundPlayList$SoundPlayerAdapter.&lt;init&gt;(SoundPlayList.java:52) 11-12 15:45:04.985: E/AndroidRuntime(5288): at com.example.soundplayer.SoundPlayList.onCreate(SoundPlayList.java:29) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 11-12 15:45:04.985: E/AndroidRuntime(5288): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 11-12 15:45:04.985: E/AndroidRuntime(5288): ... 11 more 11-12 15:45:10.105: I/Process(5288): Sending signal. PID: 5288 SIG: 9 </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