0

I am getting a crash each time i am closing app or changing tab :

FATAL EXCEPTION: main
   Process: com.pinmedia.mediaguide, PID: 30982
   java.lang.NoClassDefFoundError: rt
       at rs.<clinit>(SourceFile:17)
       at android.support.v7.widget.RecyclerView.onSaveInstanceState(SourceFile:201)
       at android.view.View.dispatchSaveInstanceState(View.java:12922)
       at android.view.ViewGroup.dispatchFreezeSelfOnly(ViewGroup.java:2763)
       at android.support.v7.widget.RecyclerView.dispatchSaveInstanceState(SourceFile:220)
       at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2749)
       at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2749)
       at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2749)
       at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2749)
       at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2749)
       at android.view.View.saveHierarchyState(View.java:12905)
       at android.support.v4.app.FragmentManagerImpl.saveFragmentViewState(FragmentManager.java:2594)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1378)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
       at android.support.v4.app.FragmentManagerImpl.dispatchDestroyView(FragmentManager.java:2943)
       at android.support.v4.app.Fragment.performDestroyView(Fragment.java:2414)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1381)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
       at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753)
       at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
       at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710)
       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:5584)
       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:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(Native Method)

I am using Horizontal RecyclerView inside that fragment :

RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.itv_submenu_recycler_view);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new SubMenuItemsAdapter(subMenuTabChangeListener);
mRecyclerView.setAdapter(mAdapter);

and recycler view is

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    android:id="@+id/itv_submenu_recycler_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" />

and I am using following library for recyclerView :

compile 'com.android.support:support-v13:25.0.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:recyclerview-v7:25.3.+'

This issue is appearing on one phone (Kitkat devices) only. Please help me to solve this crash. Thanks

NehaK
  • 2,639
  • 1
  • 15
  • 31

1 Answers1

1

your using the support library 25.3.0, it can be that the phone where the crash on appears not has the latest google play services update on his phone.

to check for that

private void checkGooglePlayServices(){
    GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    int code = api.isGooglePlayServicesAvailable(this);
    if (code == ConnectionResult.SUCCESS) {
        onActivityResult(REQUEST_GOOGLE_PLAY_SERVICES, Activity.RESULT_OK, null);
    } else if (api.isUserResolvableError(code) &&
            api.showErrorDialogFragment(this, code, REQUEST_GOOGLE_PLAY_SERVICES)) {
        // wait for onActivityResult call (see below)
    } else {

        Toast.makeText(this, api.getErrorString(code), Toast.LENGTH_LONG).show();
    }
}

and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode) {
        case REQUEST_GOOGLE_PLAY_SERVICES:
            if (resultCode == Activity.RESULT_OK) {
                loadData();
            }
            break;

        default:
            super.onActivityResult(requestCode, resultCode, data);
    }
}

what @wrkwrk sad could be a possibility but normally more phones would have problems then and not just one.

on another node try not to use the + indicator in Gradle, every time you try to build your app, Gradle has to check what the newest version is, and that only cost build-time.

quantum apps
  • 938
  • 2
  • 13
  • 25
  • on an activity call the checkGooglePlayServices this will check for you the playservices on the phone and if you need to download it. to get the responce of this override onActivityResult as given in the answer above. if Result_ok you can do what you want, if not android will send the user to the playstore to download the newest version. I use this code normally in the loading activity part to validate if everything is in order. – quantum apps Jun 16 '17 at 09:21
  • from which method I should call checkGooglePlayServices() ? – NehaK Jun 16 '17 at 09:23
  • best place is the onStart in your loading or main page. but you have to call the function before using any support lib function or the bug will happen before the service check – quantum apps Jun 16 '17 at 09:26
  • Hi @quantum apps, it is going to ConnectionResult.SUCCESS , means they are updated. and this issue is occurring only on kitkat. – NehaK Jun 16 '17 at 11:00
  • Samsung S3 or S4? – quantum apps Jun 16 '17 at 11:05
  • Samsung s4, and its appearing on Asus phone it also has kitkat. and I tested on Naughat, its working for that. – NehaK Jun 16 '17 at 11:07
  • and I noticed this crash appearing only when fragment is getting destroyed from memory. – NehaK Jun 16 '17 at 11:07