How I can fix this ?
FATAL EXCEPTION: main Process: a6e69.materialdesigntest, PID: 1981 java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompatLollipop; or its super classes (declaration of 'android.support.v4.view.ViewCompatLollipop' appears in /data/data/a6e69.materialdesigntest/files/instant-run/dex/slice-internal_impl-24.2.0_0db54c0342e0b2146307a83cef64394e5c99e6bd-classes.dex) at android.support.v4.view.ViewCompat$LollipopViewCompatImpl.setOnApplyWindowInsetsListener(ViewCompat.java:1558) at android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(ViewCompat.java:2829) at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:425) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at a6e69.materialdesigntest.MainActivity.onCreate(MainActivity.java:22) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
NavigationDrawer.java
public class NavigationDrawerFragment extends Fragment {
private RecyclerView recyclerView;
private RecycleAdapter adapter;
private boolean mUserLearnedDrawer;
private boolean mFromSavedInstanceState;
public static final String PREF_FILE_NAME="testpref";
public static final String KEY_USER_LEANERD_DRAWER="user_leanerd_drawer";
private View containerView;
ActionBarDrawerToggle mDrawerToggle;
DrawerLayout mDrawerLayout;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUserLearnedDrawer=Boolean.valueOf(readFromPreferences(getActivity(),KEY_USER_LEANERD_DRAWER,"false"));
if(savedInstanceState!=null){
mFromSavedInstanceState=true;
}
}
public NavigationDrawerFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layout=inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
recyclerView= (RecyclerView) layout.findViewById(R.id.drawerList);
adapter=new RecycleAdapter(getActivity(),getData());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return layout;
}
public static List<Information> getData(){
List<Information> data=new ArrayList<>();
int[] icons={R.drawable.abacus,R.drawable.bell,R.drawable.blackboard,R.drawable.book};
String[] titles={"abacus","bell","blackboard","book"};
for (int i=0;i<icons.length && i<titles.length;i++){
Information current=new Information();
current.iconId=icons[i];
current.title=titles[i];
data.add(current);
}
return data;
}
public void setUp(int fragmentid, DrawerLayout drawerlayout, final Toolbar tollbar) {
containerView=getActivity().findViewById(fragmentid);
mDrawerLayout=drawerlayout;
mDrawerToggle=new ActionBarDrawerToggle(getActivity(),mDrawerLayout,tollbar,R.string.drawer_open,R.string.drawer_close){
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if(!mUserLearnedDrawer){
mUserLearnedDrawer=true;
saveToPreferences(getActivity(),KEY_USER_LEANERD_DRAWER,mUserLearnedDrawer+"");
}
getActivity().invalidateOptionsMenu();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
getActivity().invalidateOptionsMenu();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
tollbar.setAlpha((float) (1-(slideOffset-.3)));
}
};
if (!mUserLearnedDrawer && !mFromSavedInstanceState){
mDrawerLayout.openDrawer(containerView );}
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
}
public static void saveToPreferences(Context context,String preferenceName,String preferenceValue){
SharedPreferences sharedpreferences=context.getSharedPreferences(PREF_FILE_NAME,context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedpreferences.edit();
editor.putString(preferenceName,preferenceValue);
editor.apply();
}
public static String readFromPreferences(Context context,String preferenceName,String defaultValue){
SharedPreferences sharedpreferences=context.getSharedPreferences(PREF_FILE_NAME,context.MODE_PRIVATE);return sharedpreferences.getString(preferenceName,defaultValue);}
manifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SubActivity">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"/>
</activity>
</application>
app
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "a6e69.materialdesigntest"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:+'}
MainActivity
public class MainActivity extends AppCompatActivity {
Toolbar appBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appBar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(appBar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navFragment);
drawerFragment.setUp(R.id.navFragment,(DrawerLayout) findViewById(R.id.drawerLayout1), appBar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.setting) {
Toast.makeText(this, "hey you just hint", Toast.LENGTH_SHORT).show();
return true;
} else if (id == R.id.next) {
startActivity(new Intent(this, SubActivity.class));
}
return super.onOptionsItemSelected(item);
}}
tnx.
Please update the following in your gradle file in the following
compileSdkVersion 24
buildToolsVersion "24.0.1"
targetSdkVersion to 24
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
Note: Please use the latest version for the libraries and avoid using + like you are doing for your recyclerview. Infact you should be getting this warning as well in android studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With