与FragmentPagerAdapter一起使用noclassdeffounderror

时间:2015-02-14 10:30:49

标签: android fragment noclassdeffounderror fragmentpageradapter fragmentmanager

我正在尝试在我的应用中对一组片段实施滑动,并且基本上是在尝试按照Android上的代码进行操作 http://developer.android.com/reference/android/support/v13/app/FragmentPagerAdapter.html  页。

但是,我收到以下错误:

02-14 19:16:34.138: I/LoginFragment(10309): setting shared preferences...
02-14 19:16:34.197: I/art(10309): Rejecting re-init on previously-failed class java.lang.Class<com.grooble.moeigo.ProfileActivity$AppSectionsPagerAdapter>
02-14 19:16:34.197: I/art(10309): Rejecting re-init on previously-failed class java.lang.Class<com.grooble.moeigo.ProfileActivity$AppSectionsPagerAdapter>
02-14 19:16:34.198: I/art(10309): Rejecting re-init on previously-failed class java.lang.Class<com.grooble.moeigo.ProfileActivity$AppSectionsPagerAdapter>
02-14 19:16:34.233: I/art(10309): Rejecting re-init on previously-failed class java.lang.Class<com.grooble.moeigo.ProfileActivity$AppSectionsPagerAdapter>
02-14 19:16:34.235: D/AndroidRuntime(10309): Shutting down VM
02-14 19:16:34.239: E/AndroidRuntime(10309): FATAL EXCEPTION: main
02-14 19:16:34.239: E/AndroidRuntime(10309): Process: com.grooble.moeigo, PID: 10309
02-14 19:16:34.239: E/AndroidRuntime(10309): java.lang.NoClassDefFoundError: com.grooble.moeigo.ProfileActivity$AppSectionsPagerAdapter
02-14 19:16:34.239: E/AndroidRuntime(10309):    at com.grooble.moeigo.ProfileActivity.onCreate(ProfileActivity.java:53)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.Activity.performCreate(Activity.java:5933)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.os.Looper.loop(Looper.java:135)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at android.app.ActivityThread.main(ActivityThread.java:5221)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at java.lang.reflect.Method.invoke(Native Method)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at java.lang.reflect.Method.invoke(Method.java:372)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-14 19:16:34.239: E/AndroidRuntime(10309):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我定义了类:

public class ProfileActivity extends Activity implements ActionBar.TabListener {

    AppSectionsPagerAdapter appSectionsAdapter;

    ViewPager viewPager;

    // other private variables

    @Override
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_activity);

    public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {

        public AppSectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            switch (i) {
                case 0:
                    return new FriendsFragment();

                default:
                    return new UserFragment();
            }
        }

        @Override
        public int getCount() {
            return 2;
        }

    }

但我怀疑这个问题可能与混合本机和支持库有关(?)以下是相关的导入:

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

可以像这样混合原生,v4和v13吗? 欢迎任何建议。

@Po姓名:我相信我有。这是构建路径的屏幕截图:

build path

这是包含ViewPager的profile_activity.xml:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

我还提供了一些可能相关的ProfileActivity代码。

0 个答案:

没有答案