@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast.makeText(getBaseContext(), "resultCode : " + requestCode, Toast.LENGTH_SHORT).show();
try{
//Uri에서 이미지 이름을 얻어온다.
//String name_str = getImageNameToUri(data.getData());
//이미지데이터를 비트맵으로 받아온다.
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData());
ImageView SelectesNC = (ImageView)findViewById(R.id.SelectedNC);
//배치해 놓은 ImageView에 set
SelectesNC.setImageBitmap(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageByte = stream.toByteArray();
Toast.makeText(getApplicationContext(), "DB에?", Toast.LENGTH_SHORT).show();
Log.d("receive", "1 : " + imageByte);
dbHandler.insertImage(imageByte);
Log.d("receive", "2 : " + imageByte);
Toast.makeText(getApplicationContext(), "DB에 저장성공", Toast.LENGTH_SHORT).show();
showImg();
Log.d("receive", "blob : " + 4);
return;
}catch (FileNotFoundException e){
//TODO Auto-generated catch block
e.printStackTrace();
Log.d("receive", "blob : " + 1);
}catch (IOException e){
//TODO Auto-generated catch block
e.printStackTrace();
Log.d("receive", "blob : " + 2);
}catch (Exception e){
e.printStackTrace();
Log.d("receive", "blob : " + 3);
}
}
이렇게 적어서 버튼을 누르고 이미지를 선택하면 그 이미지를 SelectedNC에 배치 시킵니다.
그리고 그 이미지를 byte로 변환하여 dbHandler.insertImage를 통해 저장하려 하는데요.
일단 dbHandler.insertImage에 대한 소스 보여드릴게요.
public long insertImage(byte[] image){
db = helper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("ncimg", image);
Log.w("MypageModify", String.valueOf(image));
long result = db.update("members", values, null, null);
return result;
}
이렇게 적었습니다. 그리고 실행시켜보면
09-07 20:19:44.344 1342-1342/org.androidtown.lbs.map D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
09-07 20:19:46.509 1342-1342/org.androidtown.lbs.map W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
09-07 20:19:46.779 1342-1342/org.androidtown.lbs.map V/ActivityThread﹕ updateVisibility : ActivityRecord{34fbc6fd token=android.os.BinderProxy@90dcbd5 {org.androidtown.lbs.map/org.androidtown.lbs.map.MypageModify}} show : false
09-07 20:19:47.114 1342-1463/org.androidtown.lbs.map E/OpenGLRenderer﹕ SFEffectCache:clear(), mSize = 0
09-07 20:19:52.894 1342-1342/org.androidtown.lbs.map D/receive﹕ 1 : [B@21bd293e
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'long org.androidtown.lbs.map.DBHandler.insertImage(byte[])' on a null object reference
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at org.androidtown.lbs.map.MypageModify.onActivityResult(MypageModify.java:141)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.Activity.dispatchActivityResult(Activity.java:6549)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.ActivityThread.deliverResults(ActivityThread.java:4086)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.ActivityThread.handleSendResult(ActivityThread.java:4133)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.ActivityThread.access$1400(ActivityThread.java:179)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1511)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.os.Looper.loop(Looper.java:145)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5974)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
09-07 20:19:52.904 1342-1342/org.androidtown.lbs.map D/receive﹕ blob : 3
09-07 20:19:52.939 1342-1342/org.androidtown.lbs.map I/Choreographer﹕ Skipped 33 frames! The application may be doing too much work on its main thread.
09-07 20:19:52.969 1342-1463/org.androidtown.lbs.map I/OpenGLRenderer﹕ Initialized EGL, version 1.4
09-07 20:19:52.969 1342-1463/org.androidtown.lbs.map I/OpenGLRenderer﹕ HWUI protection enabled for context , &this =0xa0722088 ,&mEglDisplay = 1 , &mEglConfig = -1601821136
09-07 20:19:52.969 1342-1463/org.androidtown.lbs.map D/mali_winsys﹕ new_window_surface returns 0x3000, [1440x2560]-format:1
09-07 20:19:53.009 1342-1463/org.androidtown.lbs.map D/mali_winsys﹕ new_window_surface returns 0x3000, [609x199]-format:1
09-07 20:19:53.289 1342-1342/org.androidtown.lbs.map I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@90dcbd5 time:108142811
09-07 20:19:54.044 1342-1463/org.androidtown.lbs.map D/mali_winsys﹕ new_window_surface returns 0x3000, [332x200]-format:1
09-07 20:20:26.019 1342-1342/org.androidtown.lbs.map V/ActivityThread﹕ updateVisibility : ActivityRecord{34fbc6fd token=android.os.BinderProxy@90dcbd5 {org.androidtown.lbs.map/org.androidtown.lbs.map.MypageModify}} show : true
09-07 20:20:26.989 1342-1342/org.androidtown.lbs.map V/ActivityThread﹕ updateVisibility : ActivityRecord{34fbc6fd token=android.os.BinderProxy@90dcbd5 {org.androidtown.lbs.map/org.androidtown.lbs.map.MypageModify}} show : false
09-07 20:20:27.779 1342-1342/org.androidtown.lbs.map W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection
09-07 20:22:15.914 1342-1463/org.androidtown.lbs.map E/OpenGLRenderer﹕ SFEffectCache:clear(), mSize = 0
로그가 이렇게 뜹니다. 보면 imageByte의 값은 [B@21bd293e 이게 맞는거죠?
근데 그 다음줄에 .DBHandler.insertImage(byte[])' on a null object reference 이렇게 뜨는걸 보면 또 null값이라고 뜨는데 왜 이렇게 뜨는건지 잘 모르겠습니다. 제발 도와주세요. 이것때문에 몇일을 멈춰있네요ㅠㅠ