简体   繁体   English

某些设备上的java.lang.NoClassDefFoundError异常

[英]java.lang.NoClassDefFoundError exception on some devices

I have an ImageView in my Fragment , on which am setting an onClick Listener . 我在Fragment有一个ImageView ,在其上设置了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;
}

This is running fine on Nexus, oneplus but I get the following error on some devices. 在Nexus,oneplus上运行正常,但在某些设备上出现以下错误。

 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)

The $1 signifies an Inner class, which is the onclicklistener . $ 1表示内部类,即onclicklistener If I comment out the onclicklistener code, the Activity and the Fragment launch fine. 如果我注释掉onclicklistener代码,则Activity和Fragment启动。 Why is this? 为什么是这样? What is the issue? 有什么问题

It seems that your app reach the limitation of 65K methods, which is quite famous limitation of Android. 您的应用似乎达到了65K方法的限制,这是Android相当著名的限制。

Ref: 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: 或简而言之:

If you have your Application class (you extends class Application), override attachBaseContext() in that class and call Multidex.install(this) 如果您有Application类(扩展了Application类),则在该类中重写attachBaseContext()并调用Multidex.install(this)

otherwise add this to your Manifest: 否则,将其添加到清单中:

android:name="android.support.multidex.MultiDexApplication"

inside <application> tag. <application>标签中。

Please reply here if it solves your problem. 如果可以解决您的问题,请在这里答复。 It solves mine actually. 它实际上解决了我的问题。

I had this issue running a Samsung Android 8.0 device, however no issue on Samsung Android 9. Enabling multidex and extending multidex application didn't help. 我在运行Samsung Android 8.0设备时遇到了此问题,但是在Samsung Android 9上却没有问题。启用multidex和扩展multidex应用程序无济于事。

The only thing that fixed it was reducing the gradle tools version from 3.5.1 to 3.4.1 (com.android.tools.build:gradle:3.4.1) 唯一解决此问题的方法是将Gradle工具的版本从3.5.1降低到3.4.1(com.android.tools.build:gradle:3.4.1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM