2013-07-09 4 views
0

내 sqlite 데이터베이스에 저장된 이미지를로드 할 수있는 메소드를 만들고 싶습니다. 내 데이터베이스에서 내가 영상과 주소 이미지 identifiant을 포함하는 테이블을 생성, 내 목표는 버튼을 여기에 에 각각의 이미지를 넣어하는 방법이다 :sqlite 데이터베이스에 저장된 이미지를로드하려면 어떻게해야합니까?

public String getImage(int i)//afficher une image 
    { 
     String res; 
     SQLiteStatement s = database.compileStatement ("SELECT " + COL_ADRESS_IMAGE + "FROM " + TABLE_IMAGE + "WHERE id_image IN (SELECT " + COL_IMAGE_CATEGORY + 
       "FROM " + TABLE_CATEGORY + "WHERE " + COL_ID_CATEGORY + "= '" +i +"')"); 
     res = s.toString(); 
     return res; 
    } 

그러나이 방법은 작동하지 않습니다, 여기 logcagt 그래도입니다 :

07-09 14:16:56.159: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:16:56.169: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:17:46.439: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:17:46.439: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:18:36.759: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:18:36.759: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:19:27.038: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:19:27.038: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:20:17.310: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:20:17.310: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:21:07.659: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:21:07.659: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:21:57.999: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:21:57.999: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:22:48.389: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:22:48.398: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:23:38.790: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:23:38.790: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:24:29.039: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:24:29.039: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:25:19.269: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:25:19.269: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:26:09.538: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:26:09.538: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:26:59.879: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:26:59.879: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:27:50.259: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:27:50.259: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:28:40.819: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:28:40.819: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:29:31.168: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:29:31.168: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:30:21.528: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:30:21.528: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:31:11.929: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:31:11.929: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:32:02.279: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:32:02.289: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:32:52.638: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:32:52.648: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:33:43.039: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:33:43.039: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:34:33.320: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:34:33.320: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:35:23.679: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:35:23.689: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:36:14.008: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:36:14.018: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:37:04.329: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:37:04.329: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:37:54.689: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:37:54.689: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:38:44.889: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:38:44.889: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:39:35.218: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:39:35.218: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:40:25.539: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:40:25.539: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:02.519: W/Trace(2236): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:16.119: W/Trace(2535): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:16.119: W/Trace(2535): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:16.129: W/Trace(2535): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:16.129: W/Trace(2535): Unexpected value from nativeGetEnabledTags: 0 
07-09 14:41:16.739: D/dalvikvm(2535): GC_FOR_ALLOC freed 59K, 7% free 2514K/2692K, paused 105ms, total 108ms 
07-09 14:41:16.829: I/dalvikvm-heap(2535): Grow heap (frag case) to 5.694MB for 3279376-byte allocation 
07-09 14:41:16.949: D/dalvikvm(2535): GC_FOR_ALLOC freed 1K, 4% free 5715K/5896K, paused 90ms, total 90ms 
07-09 14:41:17.069: D/dalvikvm(2535): GC_CONCURRENT freed <1K, 4% free 5715K/5896K, paused 11ms+26ms, total 120ms 
07-09 14:41:18.319: D/dalvikvm(2535): GC_FOR_ALLOC freed <1K, 4% free 5715K/5896K, paused 53ms, total 53ms 
07-09 14:41:18.399: I/dalvikvm-heap(2535): Grow heap (frag case) to 12.729MB for 7378576-byte allocation 
07-09 14:41:18.509: D/dalvikvm(2535): GC_CONCURRENT freed 0K, 2% free 12921K/13104K, paused 18ms+28ms, total 113ms 
07-09 14:41:18.919: D/AndroidRuntime(2535): Shutting down VM 
07-09 14:41:18.919: W/dalvikvm(2535): threadid=1: thread exiting with uncaught exception (group=0x40a70930) 
07-09 14:41:18.959: E/AndroidRuntime(2535): FATAL EXCEPTION: main 
07-09 14:41:18.959: E/AndroidRuntime(2535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.activity/com.application.activity.MainActivity}: java.lang.NullPointerException 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.os.Looper.loop(Looper.java:137) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread.main(ActivityThread.java:5039) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at java.lang.reflect.Method.invoke(Method.java:511) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at dalvik.system.NativeStart.main(Native Method) 
07-09 14:41:18.959: E/AndroidRuntime(2535): Caused by: java.lang.NullPointerException 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at com.application.database.DataBase.getImage(DataBase.java:168) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at com.application.activity.MainActivity.putLinearLayout(MainActivity.java:48) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at com.application.activity.MainActivity.onCreate(MainActivity.java:29) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.Activity.performCreate(Activity.java:5104) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
07-09 14:41:18.959: E/AndroidRuntime(2535):  ... 11 more 
+0

바이트 배열을 사용합니다. – chancea

+0

getImage가 쿼리를 반환해야합니까? (또한, 귀하의 데이터베이스는 아마도 null입니다) – njzk2

+0

즉, 내 데이터베이스의 사진을 버튼에 넣으려고합니다. – Sally

답변

0

s.ToString() 대신에 열 이름을 호출해야합니다. 귀하의 경우 s.COL_ADRESS_IMAGE 열에 동적 이름을 사용하고 있기 때문에 어떻게 작동하는지 알 수 없습니다. 내 제안은 변수없이 테스트하고, 실제 열 이름을 사용하고, 변수를 통합 할 수 있습니다.

+0

당신을 이해하지 못했습니다 : / – Sally

관련 문제