Android 在doInBackground()中执行错误
这是我显示图像和图像的地方 它是一个画布,放在imageview中,然后使用asynctask绘制 我希望你能帮我解释一下我的密码有什么问题谢谢。 但不断出现这样的错误: 这是我的代码:Android 在doInBackground()中执行错误,android,android-asynctask,Android,Android Asynctask,这是我显示图像和图像的地方 它是一个画布,放在imageview中,然后使用asynctask绘制 我希望你能帮我解释一下我的密码有什么问题谢谢。 但不断出现这样的错误: 这是我的代码: private Bitmap mImageone, mImagetwo, mImagethree, mImagefour; private Bitmap mBackground; private BitmapDrawable mBitmapDrawable; private static String mTe
private Bitmap mImageone, mImagetwo, mImagethree, mImagefour;
private Bitmap mBackground;
private BitmapDrawable mBitmapDrawable;
private static String mTempDir;
private FileOutputStream mFileOutputStream = null;
private Canvas mCanvas;
public class ImageAsyctask extends AsyncTask<Bitmap, Void, Bitmap> {
private final WeakReference<Bitmap> imageViewReference;
public ImageAsyctask(Bitmap bitmap) {
imageViewReference = new WeakReference<Bitmap>(bitmap);
}
@Override
protected Bitmap doInBackground(Bitmap... params) {
// TODO Auto-generated method stub
mTempDir = Environment.getExternalStorageDirectory()
+ "/MyCameraBooth/Photo/";
File mTempFile = new File(mTempDir);
if (!mTempFile.exists()) {
mTempFile.mkdirs();
}
mBackground = Bitmap
.createBitmap(1800, 1200, Bitmap.Config.RGB_565);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
f = new File(AppConstant.filepathone);
Bitmap mImageone = decodeFile(f);
g = new File(AppConstant.filepathtwo);
Bitmap mImagetwo = decodeFile(g);
h = new File(AppConstant.filepaththree);
Bitmap mImagethree = decodeFile(h);
i = new File(AppConstant.filepathfour);
Bitmap mImagefour = decodeFile(i);
j = new File(sharedpreferences.getString("positionImage",
"positionImage"));
Bitmap mbGG = decodeFile(j);
Bitmap mBack = Bitmap.createScaledBitmap(mbGG, 1800, 1200, true);
Bitmap mImaget = Bitmap.createScaledBitmap(mImagetwo, 515, 360,
true);
Bitmap mImageth = Bitmap.createScaledBitmap(mImagethree, 515, 360,
true);
Bitmap mImagef = Bitmap.createScaledBitmap(mImagefour, 515, 360,
true);
Bitmap mImageo = Bitmap.createScaledBitmap(mImageone, 1085, 635,
true);
mCanvas = new Canvas(mBackground);
mCanvas.drawARGB(255, 150, 150, 10);
if (sharedpreferences.getString("positionImage", "positionImage")
.contains("FrameA")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 75, null);
mCanvas.drawBitmap(mImageo, 75, 490, null);
mCanvas.drawBitmap(mImageth, 645, 75, null);
mCanvas.drawBitmap(mImagef, 1215, 75, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameB")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 75, null);
mCanvas.drawBitmap(mImageo, 645, 490, null);
mCanvas.drawBitmap(mImageth, 645, 75, null);
mCanvas.drawBitmap(mImagef, 1215, 75, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameC")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 765, null);
mCanvas.drawBitmap(mImageo, 645, 75, null);
mCanvas.drawBitmap(mImageth, 645, 765, null);
mCanvas.drawBitmap(mImagef, 1215, 765, null);
} else if (sharedpreferences.getString("positionImage",
"positionImage").contains("FrameD")) {
mCanvas.drawBitmap(mBack, 0, 0, null);
mCanvas.drawBitmap(mImaget, 75, 765, null);
mCanvas.drawBitmap(mImageo, 75, 75, null);
mCanvas.drawBitmap(mImageth, 645, 765, null);
mCanvas.drawBitmap(mImagef, 1215, 765, null);
}
Log.e(sharedpreferences.getString("positionImage", "positionImage"),
sharedpreferences.getString("positionImage",
"positionImage"));
return mBackground;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
String friendlydate = DateFormat.getTimeInstance(
DateFormat.MEDIUM).format(new Date());
friendlydate = friendlydate.replace(':', '_');
String filename = friendlydate + ".jpg";
mBitmapDrawable = new BitmapDrawable(mBackground);
Bitmap mNewSaving = mBitmapDrawable.getBitmap();
String FtoSave = mTempDir + filename;
File mFile = new File(FtoSave);
mFileOutputStream = new FileOutputStream(mFile);
mNewSaving.compress(Bitmap.CompressFormat.PNG, 100,
mFileOutputStream);
imVCature_pic.setImageBitmap(decodeSampledBitmapFromFile(
mFile.getAbsolutePath(), 150, 150));
f.delete();
i.delete();
g.delete();
h.delete();
// imVCature_pic.setImageBitmap(decodeFile(mFile));
mFileOutputStream.flush();
mFileOutputStream.close();
mFileOutputStream = null;
} catch (FileNotFoundException e) {
Log.e(AppConstant.TAG,
"FileNotFoundExceptionError " + e.toString());
} catch (IOException e) {
Log.e(AppConstant.TAG, "IOExceptionError " + e.toString());
}
Log.i(AppConstant.TAG, "Image Created");
}
}
然后运行它:
新ImageAsyctaskmBackground.execute 您的日志文件中存在由位图引起的NullPointerException。createScaledBitmap可能是您的位图mbGG、mImagetwo、mImagethree、mImagefour、mImageone中的一个为null,我打赌是从共享首选项中定义的文件加载的mbGG。当我尝试记录它时,它不是空的?您的日志表明它发生在FDisplayPhoto.java的第124行,这是什么?FDisplayPhoto的第124行是什么?它是mImaget,但现在logcat say s-SkImageDecoder::Factory返回空的?Zzzz。