버전 6.0.1 이상 버전의 서버로 사진을 보낼 수 없습니다. 제대로 작동합니다. 아래 오류가 있습니다.사진을 서버에 업로드 할 수 없음
12-20 16:37:42.888 31885-31885/com.testing E/BitmapFactory: Unable to
decode stream: java.io.FileNotFoundException:
/external_files/DCIM/Camera/JPEG_20171220_163728_946425952.jpg: open failed:
ENOENT (No such file or directory)
12-20 16:37:42.890 31885-31885/com.testing E/AndroidRuntime: FATAL
EXCEPTION: main
Process:
com.testing, PID: 31885
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean
android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat,
int, java.io.OutputStream)' on a null object reference
at
com.testing.CameraUtils.getBytes(CameraUtils.java:107)
at
com.testing.CameraUtils.saveToInternal(CameraUtils.java:124)
카메라의 Utils 클래스 코드 그것 getBytes 방법에 오류를 나타내는 내부 방법에 저장 여기서 바이트 어레이로 비트 맵으로 변환 //
public static String saveToInternal(Context context, Uri tempUri)
{
OutputStream out = null;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10;
Bitmap bmp= BitmapFactory.decodeFile(tempUri.getPath(),options);
File destinationInternalImageFile = new File(getOutputInternalMediaFile(context, 1).getPath());
byte[] bitmapdata=getBytes(bmp);
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
try {
destinationInternalImageFile.createNewFile();
out = new FileOutputStream(destinationInternalImageFile);
byte[] buf = new byte[1024];
int len;
while ((len = bs.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if (bs != null) {
bs.close();
}
if (out != null) {
bs.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Log.e(TAG, "File Size : " + (destinationInternalImageFile.length()/1024) + "KB");
return destinationInternalImageFile.getPath();
}
을
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,50, stream);
return stream.toByteArray();
}
// 변환 바이트 배열에서 비트 맵까지
public static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
코드 –
분명히 오류는 파일 또는 디렉토리에 해당 이름의 이미지가 없음을 나타냅니다. 널 (NULL)이 압축 함수로 들어갑니다. –
[NullPointerException이란 무엇이며 어떻게 수정합니까?] (https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it)) –