Android Cannot resolve method 'checkSelfPermission' in 'ContextCompat'
时间: 2023-12-28 14:04:11 浏览: 34
This error occurs when you try to use the `checkSelfPermission` method from the `ContextCompat` class in an Android project and Android Studio is unable to resolve the method.
To resolve this error, you need to make sure that you have the latest version of the `support-v4` library in your project. You can do this by adding the following line to your app's build.gradle file:
```gradle
implementation 'com.android.support:support-v4:28.0.0'
```
Once you have added this line, sync your project and try using the `checkSelfPermission` method again. It should now resolve correctly.
相关问题
Cannot resolve method 'checkSelfPermission' in 'ContextCompat'
This error message usually occurs when you are trying to use the `checkSelfPermission()` method from the `ContextCompat` class, but the method cannot be resolved. The reason for this is that the `checkSelfPermission()` method was introduced in API level 23 (Android Marshmallow) and if your app is targeting an API level lower than 23, then this method won't be available.
To fix this error, you can either:
1. Update your app's targetSdkVersion to 23 or higher in your app's build.gradle file. This will make the `checkSelfPermission()` method available.
2. Use the `ActivityCompat` class instead of `ContextCompat`, which has a similar `checkSelfPermission()` method that is available in all API levels.
For example, instead of:
```
ContextCompat.checkSelfPermission(context, permission)
```
You can use:
```
ActivityCompat.checkSelfPermission(activity, permission)
```
Make sure to import the `ActivityCompat` class at the top of your file:
```
import androidx.core.app.ActivityCompat;
```
android cannot resolve method
问题:android cannot resolve method
回答:根据提供的代码和引用内容,问题出现在跳转部分的代码中。错误提示是"Cannot resolve method 'putExtra(android.os.Bundle)'",这意味着在Intent的putExtra方法中传入的参数类型不正确。在你的代码中,你使用了putExtra方法来传递一个Bundle对象,但是putExtra方法的参数应该是一个String类型的键和对应的值。所以正确的写法应该是putExtras方法,而不是putExtra方法。所以你需要将代码修改为:
startActivity(new Intent(context, JumpWepPageActivity.class).putExtras(mBundle));
这样就能正确地传递Bundle对象了。希望这能解决你的问题。
#### 引用[.reference_title]
- *1* [Cannot resolve method 'putExtra(android.os.Bundle)' Intent界面跳转传值](https://blog.csdn.net/qq_31001287/article/details/51280781)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [安卓开发调用库函数出现的“Cannot resolve method xxx”问题](https://blog.csdn.net/qq_39408483/article/details/88088685)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)