我试图在 android 指纹应用程序中实现撤消和重做功能。我试图使用下面的代码来实现。
错误
03-26 20:42:12.020: W/System.err(28056): java.lang.NullPointerException
03-26 20:42:12.020: W/System.err(28056): at baked.soft.FirstActivity.toJPEGFile(FirstActivity.java:341)
03-26 20:42:12.020: W/System.err(28056): at baked.soft.FirstActivity.onOptionsItemSelected(FirstActivity.java:314)
第一活动
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.tools:
ll.setVisibility(LinearLayout.VISIBLE);
return true;
case R.id.import_pics:
getPhotos();
return true;
case R.id.save:
toJPEGFile();
return true;
case R.id.trash:
trash();
return true;
}
return false;
}
private void toJPEGFile() {
// TODO Auto-generated method stub
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); // ERROR 341 LINE
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
我不知道哪里错了。请帮我。提前致谢!