on-static method 'setAction(java.lang.String)' cannot be referenced from a static context
时间: 2023-10-28 22:01:23 浏览: 32
这个错误通常出现在你试图从静态方法中调用非静态方法时。静态方法属于类,而不是类的实例,因此它们不能直接访问非静态方法或变量。
这个错误的解决方法有两种:
1. 将非静态方法改为静态方法,或者将静态方法的调用方式改为实例方法的调用方式。
2. 在静态方法中创建一个类的实例,并使用该实例来调用非静态方法。例如:
```
class MyClass {
String action;
public void setAction(String action) {
this.action = action;
}
}
public class MainClass {
public static void main(String[] args) {
MyClass myClass = new MyClass();
myClass.setAction("my action");
}
}
```
这样就可以避免在静态方法中调用非静态方法时出现该错误。
相关问题
am start -a android.intent.action.VIEW -d file:///sdcard/Jwu.html -t text/html -n com.android.htmlviewer/com.android.htmlviewer.HTMLViewerActivity -e android.intent.extra.TITLE "开源声明"如何用代码写
您可以使用以下代码来启动 Android 应用程序并查看 HTML 文件:
```
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
File file = new File("/sdcard/Jwu.html");
intent.setDataAndType(Uri.fromFile(file), "text/html");
intent.setClassName("com.android.htmlviewer", "com.android.htmlviewer.HTMLViewerActivity");
intent.putExtra("android.intent.extra.TITLE", "开源声明");
startActivity(intent);
```
此代码片段将创建一个新的 Intent,设置其操作为 `ACTION_VIEW`,并将数据设置为文件的 URI 和 MIME 类型设置为 `text/html`。然后,它将指定要启动的指定应用程序的包名和类名,并设置标题为“开源声明”。最后,通过调用 `startActivity()` 方法来启动该活动。
android用shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE)微信多文件分享提示仅支持图片,但是分享的已经是jpg图片格式
如果您使用的是 `shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE)` 方法分享多个文件,其中包含 JPG 格式的图片,但是微信依然提示仅支持图片,可以尝试以下方法:
1. 检查图片文件的格式是否正确,如果图片文件已经是 JPG 格式,那么可以尝试打开图片进行预览,确保图片可以正常显示。
2. 检查图片文件的大小和分辨率是否符合微信的限制,如果图片文件过大或者分辨率过高,可能会导致微信无法分享。
3. 尝试重新打开微信或者重启手机,然后重新进行分享。
4. 如果以上方法还是无法解决问题,可以尝试通过微信的“文件传输助手”功能进行分享,这个功能支持分享不同类型的文件。
5. 如果您需要分享多个图片,可以尝试将它们打包为压缩文件再进行分享。如果您需要分享其他类型的文件,可以尝试将它们转换为图片格式后再进行分享。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![.zip](https://img-home.csdnimg.cn/images/20210720083646.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)