![](/img/trans.png)
[英]The term '-alias' is not recognized as the name of a cmdlet, function, script file, or operable program
[英]Android - function not recognized return name
我正在使用以下功能,但是在返回值“ fi”时遇到麻烦,出现以下错误:
fi can not be resolved to a variable.
这是我的功能:
public File getBitmapFromwebchartView(WebView view2) {
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
File fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
//fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
谢谢你的帮助。
如果变量fi
在return语句的范围之外,则需要在初始if
语句之外定义它。
public File getBitmapFromwebchartView(WebView view2) {
File fi = null;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
//fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
如果出现以下情况,请声明File对象:
File fi;
范例:
public File getBitmapFromwebchartView(WebView view2) {
File fi;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
那是因为您的fi
是在if clause
声明的,并且不在范围内。 做这样的事情:
public File getBitmapFromwebchartView(WebView view2) {
File fi;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
//fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.