我的代码一直有效,直到我添加第7行,此时它崩溃了。
private void registerClickCallback() {
ListView list = (ListView) findViewById(R.id.listview);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
startActivity(new Intent(getApplicationContext(), ResourcesArea.class));
}
}
});
}
有人可以告诉我在哪里找出问题所在吗?我刚刚开始使用ADT
,我不知道如何找出导致崩溃的原因。
这是logcat错误消息:
07-30 13:52:00.483: E/AndroidRuntime(1099): FATAL EXCEPTION: main
07-30 13:52:00.483: E/AndroidRuntime(1099): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
07-30 13:52:00.483: E/AndroidRuntime(1099): at org.thetutortrust.tutortrust.ResourcesArea.onCreate(ResourcesArea.java:16)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.Activity.performCreate(Activity.java:4538)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.ActivityThread.access$600(ActivityThread.java:139)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.os.Looper.loop(Looper.java:156)
07-30 13:52:00.483: E/AndroidRuntime(1099): at android.app.ActivityThread.main(ActivityThread.java:4987)
07-30 13:52:00.483: E/AndroidRuntime(1099): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 13:52:00.483: E/AndroidRuntime(1099): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 13:52:00.483: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-30 13:52:00.483: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-30 13:52:00.483: E/AndroidRuntime(1099): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
一旦检查是否将活动添加到清单中。请在清单
中的代码下面<activity
android:name="org.thetutortrust.tutortrust.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.thetutortrust.tutortrust.ResourcesArea">
</activity>
答案 1 :(得分:0)
我设法解决了这个问题。我从另一个站点复制了listview的一个例子,它使用了:
public class MainActivity extends Activity {
但我将要使用的活动:
public class MainActivity extends ActionBarActivity {
所以它崩溃了。只需将它们更改为ActionBarActivity
并添加:
import android.support.v7.app.ActionBarActivity;
现在一切正常!