我最近一直在构建一个音乐应用程序,并且一直使用一些源代码并根据我自己的规范进行定制。我完成编辑和调试,并在启动时暂停。Android音乐播放器fc和错误打开跟踪文件
调试:
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2306
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2356
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 150
ActivityThread$H.handleMessage(Message) line: 1244
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5195
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 795
ZygoteInit.main(String[]) line: 562
NativeStart.main(String[]) line: not available [native method]
Logcat Log(不能似乎得到它在这里展示的)
有人可以看看我的代码,并告诉我在哪里,香港专业教育学院出了错?
这里是我的项目类代码:
Library.java
package com.timmo.tampmusicplayer;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Library extends ListActivity {
// Songs list
public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);
ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongsManager plm = new SongsManager();
// get all songs from sdcard
this.songsList = plm.getPlayList();
// looping through playlist
for (int i = 0; i < songsList.size(); i++) {
// creating new HashMap
HashMap<String, String> song = songsList.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
R.id.songTitle });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting listitem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(),
NowPlaying.class);
// Sending songIndex to PlayerActivity
in.putExtra("songIndex", songIndex);
setResult(100, in);
// Closing PlayListView
finish();
}
});
}
}
什么是伟大的,只要你确保你感觉感谢
logcat的
3-22 23:53:21.335: E/AndroidRuntime(25591): FATAL EXCEPTION: main
03-22 23:53:21.335: E/AndroidRuntime(25591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.timmo.tampmusicplayer/com.timmo.tampmusicplayer.NowPlaying}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageButton
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread.access$600(ActivityThread.java:150)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.os.Looper.loop(Looper.java:137)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread.main(ActivityThread.java:5195)
03-22 23:53:21.335: E/AndroidRuntime(25591): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 23:53:21.335: E/AndroidRuntime(25591): at java.lang.reflect.Method.invoke(Method.java:511)
03-22 23:53:21.335: E/AndroidRuntime(25591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-22 23:53:21.335: E/AndroidRuntime(25591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-22 23:53:21.335: E/AndroidRuntime(25591): at dalvik.system.NativeStart.main(Native Method)
03-22 23:53:21.335: E/AndroidRuntime(25591): Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageButton
03-22 23:53:21.335: E/AndroidRuntime(25591): at com.timmo.tampmusicplayer.NowPlaying.onCreate(NowPlaying.java:54)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.Activity.performCreate(Activity.java:5104)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-22 23:53:21.335: E/AndroidRuntime(25591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
03-22 23:53:21.335: E/AndroidRuntime(25591): ... 11 more
你是从Eclipse运行它吗?在我看来,它实际上是因为运行时异常(可能是空指针异常或任何派生自运行时异常的异常)而停止执行,您需要让它继续执行,以便它显示实际上包含错误的logcat。 .. – DigCamara 2013-03-22 23:43:11
任何想法我怎么去做呢? – Timmo 2013-03-22 23:47:16
在您的调试视图中,按下红色断开按钮。 – wojciii 2013-03-22 23:50:29