我正在尝试制作一个SwipeMenu
. 我在一个小型测试项目中工作,但是当我尝试实现它时,出现以下错误:
03-23 13:47:04.210: D/AndroidRuntime(28825): Shutting down VM
03-23 13:47:04.210: W/dalvikvm(28825): threadid=1: thread exiting with uncaught exception (group=0x41ef02a0)
03-23 13:47:04.210: E/AndroidRuntime(28825): FATAL EXCEPTION: main
03-23 13:47:04.210: E/AndroidRuntime(28825): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.SverkerSbrg.Spendo/com.SverkerSbrg.Spendo.SwipeMenu}: java.lang.ClassNotFoundException: com.SverkerSbrg.Spendo.SwipeMenu
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread.access$700(ActivityThread.java:140)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.os.Handler.dispatchMessage(Handler.java:99)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.os.Looper.loop(Looper.java:137)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-23 13:47:04.210: E/AndroidRuntime(28825): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 13:47:04.210: E/AndroidRuntime(28825): at java.lang.reflect.Method.invoke(Method.java:511)
03-23 13:47:04.210: E/AndroidRuntime(28825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-23 13:47:04.210: E/AndroidRuntime(28825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-23 13:47:04.210: E/AndroidRuntime(28825): at dalvik.system.NativeStart.main(Native Method)
03-23 13:47:04.210: E/AndroidRuntime(28825): Caused by: java.lang.ClassNotFoundException: com.SverkerSbrg.Spendo.SwipeMenu
03-23 13:47:04.210: E/AndroidRuntime(28825): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-23 13:47:04.210: E/AndroidRuntime(28825): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-23 13:47:04.210: E/AndroidRuntime(28825): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
03-23 13:47:04.210: E/AndroidRuntime(28825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
03-23 13:47:04.210: E/AndroidRuntime(28825): ... 11 more
这是我的课:
package com.SverkerSbrg.Spendo.Graphics;
import com.SverkerSbrg.Spendo.R;
import com.SverkerSbrg.Spendo.Graphics.TransactionList.*;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
public class SwipeMenu extends FragmentActivity {
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.swipe_menu_layout);
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
@Override
public void onBackPressed() {
if (mPager.getCurrentItem() == 0) {
// If the user is currently looking at the first step, allow the
// system to handle the
// Back button. This calls finish() on this activity and pops the
// back stack.
super.onBackPressed();
} else {
// Otherwise, select the previous step.
mPager.setCurrentItem(mPager.getCurrentItem() - 1);
}
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return new TransactionList();
}
@Override
public int getCount() {
return 2;
}
}
}
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SverkerSbrg.Spendo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.SverkerSbrg.Spendo.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.SverkerSbrg.Spendo.Menu"
android:label="@string/title_activity_menu" >
</activity>
<activity
android:name="com.SverkerSbrg.Spendo.SwipeMenu"
android:label="@string/title_activity_swipe_menu" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
非常感谢所有帮助:)