hai, i want to display many song using list view now i am create but its not working some problem in my coding help me what mistake i made when i run the emulator will display The application mexample (process mexample.mexample)has stopped unexpectedly. please try again
my log cat error is
10-27 21:26:36.847: INFO/ActivityManager(58): Start proc mexample.mexample for activity mexample.mexample/.Music: pid=1129 uid=10040 gids={} 10-27 21:26:36.877: INFO/AndroidRuntime(1122): NOTE: attach of thread 'Binder Thread #3' failed 10-27 21:26:37.887: DEBUG/AndroidRuntime(1129): Shutting down VM 10-27 21:26:37.897: WARN/dalvikvm(1129): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): FATAL EXCEPTION: main 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): java.lang.RuntimeException: Unable to start activity ComponentInfo{mexample.mexample/mexample.mexample.Music}: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 10-27 21:26:37.937: ERROR/AndroidRuntime(1129): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
package mexample.mexample;
import android.app.ListActivity; import java.util.ArrayList; import java.util.List; import android.media.MediaPlayer; import android.os.Bundle; import java.io.IOException; import android.view.View; import android.util.Log; import java.io.File; import android.widget.ArrayAdapter; import java.io.FilenameFilter; import android.widget.ListAdapter; import android.widget.ListView; import android.media.MediaPlayer.OnCompletionListener;
public class Music extends ListActivity {
private static final String MEDIA_PATH = new String("/data/VideoThumbnails/");
private List<String> songs = new ArrayList<String>();
private MediaPlayer mp = new MediaPlayer();
private int currentPosition = 0;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mediaplayer_1);
updateSongList();
}
public void updateSongList() {
File home = new File(MEDIA_PATH);
if (home.listFiles(new Mp3Filter()).length > 0) {
for (File file : home.listFiles(new Mp3Filter())) {
songs.add(file.getName());
}
ArrayAdapter<String> mediaplayer_1 = new ArrayAdapter<String>(this,
R.layout.song_item, songs);
setListAdapter(mediaplayer_1);
}
}
class Mp3Filter implements
FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".mp3"));
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
currentPosition = position;
playSong(MEDIA_PATH + songs.get(position));
}
private void playSong(String songPath) {
try {
mp.reset();
mp.setDataSource(songPath);
mp.prepare();
mp.start();
// Setup listener so next song starts automatically
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
nextSong();
}
});
} catch (IOException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
private void nextSong() {
if (++currentPosition >= songs.size()) {
// Last song, just reset currentPosition
currentPosition = 0;
}
else {
// Play next song
playSong(MEDIA_PATH + songs.get(currentPosition));
}
}
};
embdes@embdes-laptop:~$ cd /home/embdes/projects/android/android-sdk-linux_86/toolsembdes@embdes-laptop:~/projects/android/android-sdk-linux_86/tools$ ./adb push /home/embdes/unnai.mp3 /data/VideoThumbnails
671 KB/s (2555904 bytes in 3.718s) embdes@embdes-laptop:~/projects/android/android-sdk-linux_86/tools$