在某些设备上java.lang.NoClassDefFoundError的例外 [英] java.lang.NoClassDefFoundError exception on some devices

查看:586
本文介绍了在某些设备上java.lang.NoClassDefFoundError的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ImageView 在我的片段,其上正在设置一个的onClick监听器

I have an ImageView in my Fragment, on which am setting an onClick Listener.

public class TutorialFragment extends Fragment {

private TutorialAdapter tutorialAdapter;
private TutorialFragment tutorialFragment;
private SplashActivity splashActivity;
private RelativeLayout firstPageRelativeLayout,secondPageRelativeLayout,thirdPageRelativeLayout;
private ImageView backgroundImageView,facebookLoginButton,dekkohLogoImageView;
private ProgressDialogHandler progressDialogHandler;
private AlertDialogHandler alertDialogHandler;
private TextView firstPageTextView,secondPageTextView,thirdPageTextView,facebookPrivacyText,facebookDescriptionText;


@Override
public View onCreateView(LayoutInflater layoutInflater,ViewGroup container, Bundle savedInstanceState) {

    super.onCreateView(layoutInflater,container,savedInstanceState);

    tutorialFragment=this;
    splashActivity = (SplashActivity) getActivity();

    View v = layoutInflater.inflate(R.layout.tutorial_fragment,container,false);
    firstPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.firstScreenRelativeLayout);
    secondPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.secondScreenRelativeLayout);
    thirdPageRelativeLayout = (RelativeLayout) v.findViewById(R.id.thirdScreenRelativeLayout);
    backgroundImageView = (ImageView) v.findViewById(R.id.tutorialImageView);
    facebookLoginButton = (ImageView) v.findViewById(R.id.facebook_login_button);
    dekkohLogoImageView = (ImageView) v.findViewById(R.id.dekkohLogoImage);

    firstPageTextView = (TextView) v.findViewById(R.id.firstPageTextView);
    secondPageTextView = (TextView) v.findViewById(R.id.secondPageTextView);
    thirdPageTextView = (TextView) v.findViewById(R.id.thirdPageTextView);
    facebookPrivacyText = (TextView) v.findViewById(R.id.facebookPrivacyText);
    facebookDescriptionText = (TextView) v.findViewById(R.id.facebookDescriptionText);

    int currentIndex = (int) this.getArguments().getSerializable("tutorial");
    switch (currentIndex){
        case 0:
            firstPageRelativeLayout.setVisibility(View.VISIBLE);
            secondPageRelativeLayout.setVisibility(View.GONE);
            thirdPageRelativeLayout.setVisibility(View.GONE);
            Picasso.with(splashActivity).load(R.drawable.tutorial_1).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);
            Picasso.with(splashActivity).load(R.drawable.dekkoh_logo_tutorial).priority(Picasso.Priority.HIGH).fit().into(dekkohLogoImageView);
            break;
        case 1:
            firstPageRelativeLayout.setVisibility(View.GONE);
            secondPageRelativeLayout.setVisibility(View.VISIBLE);
            thirdPageRelativeLayout.setVisibility(View.GONE);
            Picasso.with(splashActivity).load(R.drawable.tutorial_2).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);

            break;
        case 2:
            firstPageRelativeLayout.setVisibility(View.GONE);
            secondPageRelativeLayout.setVisibility(View.GONE);
            thirdPageRelativeLayout.setVisibility(View.VISIBLE);
            Picasso.with(splashActivity).load(R.drawable.tutorial_3).priority(Picasso.Priority.HIGH).fit().into(backgroundImageView);
            Picasso.with(splashActivity).load(R.drawable.fb_login_btn).fit().into(facebookLoginButton);

            break;
    }
    final ArrayList<String> permissions = new ArrayList<String>();
    progressDialogHandler = ProgressDialogHandler.getInstance();
    alertDialogHandler = AlertDialogHandler.getInstance();


    facebookLoginButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                // setting facebook permission
                permissions.add("email");
                // permissions.add("user_location");
                permissions.add("user_friends");
                progressDialogHandler.showCustomProgressDialog(splashActivity);

                final JSONObject jb = new JSONObject();

                Session.openActiveSession(splashActivity, true,
                        permissions, new Session.StatusCallback() {

                            @SuppressWarnings("deprecation")
                            @Override
                            public void call(final Session session,
                                             SessionState state, Exception exception) {

                                if (session.isOpened()) {

                                    Request.executeMeRequestAsync(
                                            session,
                                            new Request.GraphUserCallback() {

                                                @Override
                                                public void onCompleted(
                                                        GraphUser user,
                                                        Response response) {
                                                    if (user != null) {


                                                        String emaila = user
                                                                .asMap()
                                                                .get("email")
                                                                .toString();
                                                        String userId = user
                                                                .getId();
                                                        String name1 = user
                                                                .getName();

                                                        try {

                                                            jb.put("provider",
                                                                    "Facebook");
                                                            jb.put("user_id",
                                                                    userId.toString());
                                                            String token = session
                                                                    .getAccessToken()
                                                                    .toString();
                                                            jb.put("token",
                                                                    token);

                                                            Log.d("f b login ",
                                                                    jb.toString());

                                                            // clear seesion
                                                            // details and
                                                            // close
                                                            session.closeAndClearTokenInformation();
                                                            new LoginTheUser(
                                                                    token,
                                                                    user.getId())
                                                                    .execute();

                                                        } catch (JSONException e) {
                                                            // Toast.makeText(getApplicationContext(),
                                                            // e.getLocalizedMessage(),
                                                            // Toast.LENGTH_SHORT).show();
                                                            e.printStackTrace();
                                                        }
                                                    } else {
                                                        progressDialogHandler
                                                                .dismissCustomProgressDialog(splashActivity);
                                                        alertDialogHandler
                                                                .showToast(
                                                                        splashActivity,
                                                                        "Facebook Login Failed!");
                                                    }
                                                }
                                            });
                                } else {
                                }
                            }
                        });

            }
        });

    Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(),"fonts/SortsMillGoudy-Regular.ttf");
    firstPageTextView.setTypeface(typeface);
    secondPageTextView.setTypeface(typeface);
    thirdPageTextView.setTypeface(typeface);
    facebookDescriptionText.setTypeface(typeface);
    facebookPrivacyText.setTypeface(typeface);
    return v;
}

这是在Nexus运行良好,oneplus但我得到的一些设备下面的错误。

This is running fine on Nexus, oneplus but I get the following error on some devices.

 java.lang.NoClassDefFoundError: com.myapp.fragments.TutorialFragment$1
        at com.myapp.fragments.TutorialFragment.onCreateView(TutorialFragment.java:135)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
        at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:16497)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
        at android.view.View.measure(View.java:16497)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
        at android.view.Choreographer.doCallbacks(Choreographer.java:574)
        at android.view.Choreographer.doFrame(Choreographer.java:544)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

在$ 1表示一个内部类,这是 onclicklistener 。如果我注释掉 onclicklistener code,活动和片段启动的罚款。为什么是这样?问题是什么?

The $1 signifies an Inner class, which is the onclicklistener. If I comment out the onclicklistener code, the Activity and the Fragment launch fine. Why is this? What is the issue?

推荐答案

看来,您的应用程序达到65K方法的局限性,这是Android系统颇负盛名的限制。

It seems that your app reach the limitation of 65K methods, which is quite famous limitation of Android.

参考:<一href=\"https://developer.android.com/tools/building/multidex.html#dev-build\">https://developer.android.com/tools/building/multidex.html#dev-build

您可以按照上面的链接解决方案。或简称:

You can follow the solution in above link. Or in short:

如果你有你的应用程序类(您扩展类应用程序),在类中重写attachBaseContext(),并调用Multidex.install(本)

If you have your Application class (you extends class Application), override attachBaseContext() in that class and call Multidex.install(this)

否则添加到您的清单:

的android:NAME =android.support.multidex.MultiDexApplication

&lt;应用方式&gt; 标签

请回复在这里,如果它解决您的问题。它解决了我的实际。

Please reply here if it solves your problem. It solves mine actually.

这篇关于在某些设备上java.lang.NoClassDefFoundError的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆