gpt4 book ai didi

java - 未知变量或字段 imageURL

转载 作者:行者123 更新时间:2023-11-30 00:46:05 25 4
gpt4 key购买 nike

我正在使用上下文菜单在 Web View 中查找图像...这是我通过 webviews 上的上下文菜单保存图像的代码 -

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);

WebView webView = (WebView) v;
HitTestResult hr = webView.getHitTestResult();

//Setting Hit-Tests to go for Images Only!
int type = hr.getType();

String imageUrl = hr.getExtra();

if (type == HitTestResult.IMAGE_TYPE || type == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {


menu.setHeaderTitle("Context Menu");
menu.add(0, v.getId(), 0, "Save");

}
}


@Override
public boolean onContextItemSelected(MenuItem item)
{
if(item.getTitle()== "Save")
{
//File & Folder Structure on your SdCard to Save Images
File file = new File
(Environment.getExternalStorageDirectory() + "/XYZ/");
if (!file.isDirectory())
{
file.mkdirs(); //If folder doesn't exist, this will Create One! :)
}



//Final Output will be "Your App Folder/Image name.jpg"
File savePic = new File (file, getFilenameFromURL(imageUrl));


//Setting up Download Manager to Show Image Download on Notif Panel/Status Bar :)
DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imageUrl));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setDestinationUri(Uri.fromFile(savePic));
request.setTitle("XYZ"); //Title Visible during Image Download
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadManager.enqueue(request);

Toast.makeText(this,"Action 1 invoked", Toast.LENGTH_SHORT).show();
}
return true;
}



protected String getFilenameFromURL(URL url) {
return getFilenameFromURL(url.getFile());
}

protected String getFilenameFromURL(String url) {
String[] p = url.split("/");
String s = p[p.length - 1];
if (s.indexOf("?") > -1) {
return s.substring(0, s.indexOf("?"));
}
return s;
}

但是我收到错误未知变量或字段“imageURL”,如何解决这个问题?

最佳答案

如果这正是您收到的错误消息,那么您在某处存在“拼写错误”。在您的声明中,变量是 'camelCase'

String  imageUrl = ...

不是

String  imageURL = ...

还没有看到错误,但是错误发生在哪一行?

编辑:

在类的开头声明变量:(例如)

String imageUrl = "";

然后从您当前的声明中删除“字符串”(在 onCreateContextMenu 中),使其看起来像:

imageUrl = hr.getExtra();

关于java - 未知变量或字段 imageURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41789280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com