我是 Android 开发的新手。最近试图让我自己的 Facebook 像滑出菜单一样,但无法让它工作,它在 eclipse 检查和构建中不包含任何错误,但是当我在模拟器上运行它时,模拟器给了我一个强制关闭错误只是没有原因。已经做了很多这是我遵循Johnkil Sidenavigation的教程
已经对调试技术进行了一些研究,但不知道我应该从哪里开始, 但我认为这只是我的布局问题,我错过了什么? 这是我的代码的一部分,请让我知道我需要提供什么样的信息
MainActivity.java
package com.nazartt.johntest;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import android.os.Bundle;
public class MainActivity extends SherlockActivity {
SideNavigationView sideNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SideNavigationView sideNavigationView = (SideNavigationView)findViewById(R.id.side_navigation_view);
sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
sideNavigationView.toggleMenu();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
这是我相关的 xml 代码的一部分
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<com.devspark.sidenavigation.SideNavigationView
android:id="@+id/side_navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这是插入菜单文件夹... side_navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</menu>
这是logcat,
12-28 05:29:33.643: E/Trace(11550): error opening trace file: No such file or directory (2)
12-28 05:29:33.656: E/AndroidRuntime(11550): FATAL EXCEPTION: main
12-28 05:29:33.656: E/AndroidRuntime(11550): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nazartt.johntest/com.nazartt.johntest.MainActivity}: java.lang.ClassNotFoundException: com.nazartt.johntest.MainActivity
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.os.Looper.loop(Looper.java:137)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-28 05:29:33.656: E/AndroidRuntime(11550): at java.lang.reflect.Method.invokeNative(Native Method)
12-28 05:29:33.656: E/AndroidRuntime(11550): at java.lang.reflect.Method.invoke(Method.java:511)
12-28 05:29:33.656: E/AndroidRuntime(11550): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-28 05:29:33.656: E/AndroidRuntime(11550): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-28 05:29:33.656: E/AndroidRuntime(11550): at dalvik.system.NativeStart.main(Native Method)
12-28 05:29:33.656: E/AndroidRuntime(11550): Caused by: java.lang.ClassNotFoundException: com.nazartt.johntest.MainActivity
12-28 05:29:33.656: E/AndroidRuntime(11550): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-28 05:29:33.656: E/AndroidRuntime(11550): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-28 05:29:33.656: E/AndroidRuntime(11550): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
12-28 05:29:33.656: E/AndroidRuntime(11550): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
12-28 05:29:33.656: E/AndroidRuntime(11550): ... 11 more
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nazartt.johntest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light" >
<activity
android:name="com.nazartt.johntest.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="com.actionbarsherlock.ActionBarSherlock"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.nazartt.johntest.ISideNavigationCallback"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.nazartt.johntest.SideNavigationItem"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.nazartt.johntest.SideNavigationView"
android:label="@string/app_name" >
</activity>
</application>
</manifest>