我有这个程序,这是完美的工作,直到使用应用程序的业务买大家华为Y5lite运行Android走,然后应用程序开始同时服用图像破碎。我一直在试图破解这最后四天,但没有成功。坠机事件是随机的,不遵循任何模式,即该应用可以采取几个图像,而不在某个时刻崩溃这让我觉得我的活动正在后台和相机上的前景时这样onActivityResult失败被杀,然后崩溃。我试图保存图像URL和的onSaveInstanceState检索它的onCreate但不解决它下面是我的相关代码和错误
private void launchCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = BitmapUtils.createTempImageFile(this);
} catch (IOException ex) {
ex.printStackTrace();
}
if (photoFile != null) {
mTempPhotoPath = photoFile.getAbsolutePath();
// Get the content URI for the image file
Uri photoURI = FileProvider.getUriForFile(this,
FILE_PROVIDER_AUTHORITY,
photoFile);
// Add the URI so the camera can store the image
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
// Launch the camera activity
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
//saving the filename incase activity is killed
@Override
public void onSaveInstanceState(Bundle bundle)
{
super.onSaveInstanceState(bundle);
bundle.putString("fileName", mTempPhotoPath);
}
//retrieving file name onCreate
if (savedInstanceState != null){
mTempPhotoPath = savedInstanceState.getString("fileName");}
// processing the image
private void processAndSetImage() {
switch (imageTaken) {
case "imageOne":
//I did the try-catch to see if I can isolate the issue but still crashes
try{
mAddImageOne.setVisibility(View.GONE);
mResultsBitmap = BitmapUtils.resamplePic(this, mTempPhotoPath);
mOneView.setVisibility(View.VISIBLE);
mOneView.setImageBitmap(mResultsBitmap);
findViewById(R.id.front_image_text).setVisibility(View.VISIBLE);
findViewById(R.id.save_cancel).setVisibility(View.VISIBLE);
}catch (Exception e){
Toast toast = Toast.makeText(getApplicationContext(), "Please try take the picture again",
Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM, 0, 1100);
toast.show();
}
break;
case "imageTwo":
try{
mAddImageTwo.setVisibility(View.GONE);
mTwoView.setImageBitmap(mResultsBitmap);
mResultsBitmap = BitmapUtils.resamplePic(this, mTempPhotoPath);
findViewById(R.id.front_image_label_text).setVisibility(View.VISIBLE);
findViewById(R.id.save_cancel).setVisibility(View.VISIBLE);
mTwoView.setVisibility(View.VISIBLE);
}catch (Exception e){
Toast toast = Toast.makeText(getApplicationContext(), "Please try take the picture again",
Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM, 0, 1100);
toast.show();
}
break;
}
下面是当发生崩溃时,我收到错误。 (有时照片拍摄和处理好出现,在某个时候发生了碰撞)
02-05 13:53:22.139 23081-23086 / com.avigail.tuborg I /合子:执行部分编码的高速缓存集合,代码= 25KB,数据= 30KB 02-05 13:53:22.140 23081-23086 / com.avigail。杜柏I /合子:经过代码高速缓存集合,代码= 25KB,数据= 30KB 02-05 13:53:22.141 23081-23086 / com.avigail.tuborg I /合子:增加代码高速缓存容量到128KB 02-05 13时53分:22.277 23081-23081 / com.avigail.tuborg d / AndroidRuntime:关闭VM 02-05 13:53:22.284 23081-23081 / com.avigail.tuborg E / AndroidRuntime:致命异常:主要过程:com.avigail.tuborg ,PID:23081了java.lang.RuntimeException:无法恢复活动{com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:了java.lang.RuntimeException:失败递送结果ResultInfo {谁= NULL,请求= 1 ,结果= -1,数据= NULL}到{活动com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:显示java.lang.NullPointerException:尝试调用虚拟方法“INT java.lang.String.hashCode ()”上在android.app.Activ空对象引用ityThread.performResumeActivity(ActivityThread.java:3844)在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053)在android.app.ActivityThread.-wrap11(未知来源:0)在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)在android.os.Handler.dispatchMessage(Handler.java:106)在android.os.Looper.loop(Looper.java: 166)在android.app.ActivityThread.main(ActivityThread.java:6861)在java.lang.reflect.Method.invoke(本机方法)在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java: 450)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)引起的:了java.lang.RuntimeException:失败递送结果ResultInfo {谁= NULL,请求= 1,结果= -1,数据=空}到{活动com.avigail.tuborg / com.avigail.kaskazi.activities.StockistActivity}:显示java.lang.NullPointerException:尝试调用虚拟方法 '诠释java.lang.String.hashCode()的' o NA在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3884)在android.app.ActivityThread.deliverResults(ActivityThread.java:4564)空对象引用在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053)在android.app.ActivityThread.-wrap11(未知来源:0)在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1777)在android.os .Handler.dispatchMessage(Handler.java:106)在android.os.Looper.loop(Looper.java:166)在android.app.ActivityThread.main(ActivityThread.java:6861)在java.lang.reflect.Method中。 Java的:在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:450)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)所致调用(本机方法)。 lang.NullPointerException:尝试在
com.avigail.kaskazi.activities.StockistActivity.processAndSetImage(StockistActivity.java:392)
上的空对象引用调用虚拟方法“诠释java.lang.String.hashCode()”在com.avigail.kaskazi.activities.StockistActivity.onActivityResult(StockistActivity.java:377)
一个吨android.app.Activity.dispatchActivityResult(Activity.java:7393)在android.app.ActivityThread.deliverResults(ActivityThread.java:4560)在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)在android.app。 ActivityThread.handleResumeActivity(ActivityThread.java:3884)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3053)在android.app.ActivityThread.-wrap11(未知来源:0)在android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1777)在android.os.Handler.dispatchMessage(Handler.java:106)在android.os.Looper.loop(Looper.java:166)在android.app.ActivityThread.main(ActivityThread.java: 6861)在java.lang.reflect.Method.invoke(本机方法)在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:450)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
我将非常感谢您的帮助PS:我有看到解决这一问题,但没有答案的奋力包括检查,如果数据是空的各种问题(我的数据为空,因为我把额外的选项),保存图像URL的onSaveInstanceState,ZNC检查如果intentfor结果返回OK
事实证明,这是一个相当愚蠢的错误,我花了好几天。如我所预期的问题是在后台,并将该溶液恰当地保存状态被杀害我的活动。
我节省了IMAGEURL,好吧,但缺少在被检查其图像开关变量已被抓获
switch (imageTaken) {
case "imageOne":
所以加入的onSaveInstanceState变化并适当地调用它的onCreate解决了这个问题
@Override
public void onSaveInstanceState(Bundle bundle)
{
super.onSaveInstanceState(bundle);
bundle.putString("fileName", mTempPhotoPath);
bundle.putString("imageTaken", imageTaken);
}
如果您在这里找到,因为类似的问题的自己,检查是否有不变量不会与柜面您的活动的值重新初始化。
好处是,整个问题帮我优化图像尺寸,以及位图处理过程中的内存使用情况