同様のスタックオーバーフローから次のことを試しました Clean ,Build Project Restart Eclipse
また、すべてを更新しようとしました:SDKおよびEclipseプラグインからエミュレーターを再起動するなど
ログ猫の出力:
09-26 22:11:49.182: E/AndroidRuntime(1393): FATAL EXCEPTION: main
09-26 22:11:49.182: E/AndroidRuntime(1393): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ass2/com.example.ass2.MP3Player}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.os.Looper.loop(Looper.java:137)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-26 22:11:49.182: E/AndroidRuntime(1393): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 22:11:49.182: E/AndroidRuntime(1393): at java.lang.reflect.Method.invoke(Method.java:511)
09-26 22:11:49.182: E/AndroidRuntime(1393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-26 22:11:49.182: E/AndroidRuntime(1393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-26 22:11:49.182: E/AndroidRuntime(1393): at dalvik.system.NativeStart.main(Native Method)
09-26 22:11:49.182: E/AndroidRuntime(1393): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
09-26 22:11:49.182: E/AndroidRuntime(1393): at com.example.ass2.MP3Player.onCreate(MP3Player.java:30)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.Activity.performCreate(Activity.java:5104)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-26 22:11:49.182: E/AndroidRuntime(1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-26 22:11:49.182: E/AndroidRuntime(1393): ... 11 more
コード
public class MP3Player extends Activity{
Button prev , play , stop , next , choosefiles;
ArrayAdapter<Song> adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.mp3player);
//Bitmap mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);
prev =(Button)findViewById(R.id.prev);
play =(Button)findViewById(R.id.play);
stop =(Button)findViewById(R.id.stop);
next =(Button)findViewById(R.id.next);
prev.setOnClickListener(new OnPress());
play.setOnClickListener(new OnPress());
stop.setOnClickListener(new OnPress());
next.setOnClickListener(new OnPress());
List<Song> playlist = new ArrayList<Song>();
System.out.println("Before adapter on creat");
Song test= new Song("sakis","rouvas","name","path");
playlist.add(test);
ListView list = (ListView) findViewById(R.id.listview);
adaptor = new ArrayAdapter<Song>(this,
R.layout.list_row, playlist);
list.setAdapter(adaptor);
registerForContextMenu(list);
System.out.println("after adapter on craet");
} `