我已经在大约25台设备上测试了这段代码,除了我现在要测试的三星Galaxy Nexus外,它在所有这些设备上运行良好。
这是方法,我道歉没有修改它以找到抛出异常的确切位置,但是eclipse的调试是doodoo。
private void setupImageView() {
imageLocation = currentPhotoPath;
// Get the dimensions of the View
Display display = getWindowManager().getDefaultDisplay();
Point size = getDisplaySize(display);
int targetW = size.x;
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageLocation, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW / targetW, photoH / targetW);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(imageLocation, bmOptions);
//int rotationForImage = getRotationForImage(imageLocation);
int rotationForImage = (whichCamera == 0 ? 90 : 270);
if (rotationForImage != 0) {
int targetWidth = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getHeight() : bitmap.getWidth();
int targetHeight = rotationForImage == 90 || rotationForImage == 270 ? bitmap.getWidth() : bitmap.getHeight();
Bitmap rotatedBitmap = Bitmap.createBitmap(targetWidth, targetHeight, bitmap.getConfig());
Canvas canvas = new Canvas(rotatedBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(rotationForImage, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
canvas.drawBitmap(bitmap, matrix, new Paint());
bitmap.recycle();
bitmap = rotatedBitmap;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
try
{
File f = new File(imageLocation);
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
}
catch(java.io.IOException e){}
}
imageView.setImageBitmap(bitmap);
}
任何人都知道三星与nexus的不同之处会导致此异常吗?它在Galaxy S III上运行良好
答案 0 :(得分:0)
看起来你提到的if块中的东西正在抛出NPE - 这就是真正的错误。不要担心下游和NPE触发的Activity / ResultInfo内容。逐行进行并查找空引用: - )
关于Eclipse - 遗憾的是我没有太多经验。对于Android,我个人使用IntelliJ,调试效果很好。您是否能够调试其他Java代码(甚至是简单的Hello,World)?