I got this error when I tried to debug my app
java.lang.NoSuchMethodError: No virtual method requestPermissions([Ljava/lang/String;I)V in class Lcom/cscodetech/townclap/activity/LoginActivity; or its super classes (declaration of 'com.zestar.myclip.activity.LoginActivity' appears in /data/app/com.zestar.myclip-1/base.apk:classes2.dex)
at com.zestar.myclip.activity.LoginActivity.onCreate(LoginActivity.java:92)
The logcat pointed to this line of code
requestPermissions(new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 1);
What is wrong with that line
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
FirebaseApp.initializeApp(this);
requestPermissions(new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 1);
custPrograssbar = new CustPrograssbar();
sessionManager = new SessionManager(LoginActivity.this);
atCode.setOnFocusChangeListener((view, b) -> {
if (!b) {
// on focus off
String str = atCode.getText().toString();
ListAdapter listAdapter = atCode.getAdapter();
for (int i = 0; i < listAdapter.getCount(); i++) {
String temp = listAdapter.getItem(i).toString();
if (str.compareTo(temp) == 0) {
return;
}
}
atCode.setText("");
}
});
getCodelist();
}
2
Answers
as
requestPermissions
like @TylerV said, try using this way insteadas instructed in
Documentation for how to request app permissions | Android Developers
this should be the right way to request permissions in fragments which goes as this:
Please provide your logs when exception occurs. Maybe error is because of android version. You must check if android version is bigger than Api level 26 (Marshmallow):