Jump to content

Recommended Posts

Dans ma application androïde, J'ai crée une méthode qui permet de déterminer le chemin des images stockés dans ma base de donnée SQLite .

Cette méthode ne fonctionne pas et je ne c'est pas c'est ou l'erreur

public String getImage(int id)//afficher une image
   {
 database = DBHelper.getReadableDatabase(); // open database to perform some operation
 Cursor c = database.rawQuery("SELECT " + COL_ADRESS_IMAGE + "FROM "
 + TABLE_IMAGE + "WHERE " + COL_ID_IMAGE +" IN (SELECT " + COL_IMAGE_CATEGORY + "FROM "
   + TABLE_CATEGORY + "WHERE " + COL_ID_CATEGORY + "= '" + id +"')",null );

 if(c.moveToFirst())
 { //Edited based on suggestion from SAM
	    String strCatName = c.getString(c.getColumnIndex(COL_ADRESS_IMAGE ));
		 c.close();
		 database.close();
	    return strCatName;
	  }
 else
 {
  return "";
  }

merci d'avance :)

Share this post


Link to post
Share on other sites

sans plus d'infos ca va etre dur.

il se passe quoi quand tu lance la requete ?

Share this post


Link to post
Share on other sites

Il faudrait surtout poster cela dans la section développement et pas ici...

Share this post


Link to post
Share on other sites

Je transfère

Share this post


Link to post
Share on other sites

mis à part si tes variables COL_ADRESS_IMAGE et autres se terminent par des espaces il te manque déjà des espaces devant les mots clés FROM et WHERE

ensuite le mieux est d'avoir les traces en effet

ensuite si ton id n'est pas une string en base, il ne faut pas mettre l'entouré de '

Edited by elmarco06
  • Like 1

Share this post


Link to post
Share on other sites

Je veux savoir si le syntaxe est correcte ou non !!

Lorsque je fais le débogage, il est bloqué au niveau de la requête.

Plus d'information:j'ai crée une base de données SQLite qui contient deux tableaux :tableaux pour les catégories et tableaux pour les images qui contient les adress

//tableau category
   private static final String CREATE_BD_CATEGORY="CREATE TABLE "
	 + TABLE_CATEGORY + " (" +
  COL_ID_CATEGORY + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
  COL_CATEGORY_NAME + " TEXT NOT NULL, " +
  COL_IMAGE_CATEGORY + " TEXT," +
  " FOREIGN KEY ("+COL_IMAGE_CATEGORY+") REFERENCES "+ TABLE_IMAGE +" ("+COL_ID_IMAGE +")); " ;
   //tableau image
   private static final String CREATE_BD_IMAGE="CREATE TABLE "
	    + TABLE_IMAGE + " (" +
  COL_ID_IMAGE + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
  COL_ADRESS_IMAGE + " TEXT NOT NULL ); " ;

Je veux charger les images stockés dans la base et l'utilisé dans un bouton, donc j'ai crée cette méthode ci dessus pour récupérer l'@ de l'image, mais comme j'ai déja dit elle ne fonctionne pas

Au niveau du Main_activity j'ai crée un bouton image, et je veux que ce bouton contient une image de la base .

Après compilation, l'interface s'ouvre et les boutons s'affichent mais sans image :(

Voici le code:

ImageButton b1= new ImageButton(this);
String image = db.getImage(i);
b1.setImageURI(Uri.parse(image));

Voici qu'est ce qu'il affiche le logcat:

07-12 10:36:42.739: E/BitmapFactory(952): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/fish: open failed: ENOENT (No such file or directory)
07-12 10:47:50.729: E/AndroidRuntime(3073): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.activity/com.application.activity.MainActivity}: java.lang.NullPointerException
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.os.Looper.loop(Looper.java:137)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread.main(ActivityThread.java:5039)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at java.lang.reflect.Method.invokeNative(Native Method)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at java.lang.reflect.Method.invoke(Method.java:511)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at dalvik.system.NativeStart.main(Native Method)
07-12 10:47:50.729: E/AndroidRuntime(3073): Caused by: java.lang.NullPointerException
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.net.Uri.withAppendedPath(Uri.java:2290)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at com.application.activity.MainActivity.putLinearLayout(MainActivity.java:56)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at com.application.activity.MainActivity.onCreate(MainActivity.java:31)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.Activity.performCreate(Activity.java:5104)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-12 10:47:50.729: E/AndroidRuntime(3073):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-12 10:47:50.729: E/AndroidRuntime(3073):  ... 11 more
07-12 10:47:59.158: I/Process(3073): Sending signal. PID: 3073 SIG: 9
07-12 10:49:56.429: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.441: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.449: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.889: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.889: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.908: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:56.908: W/Trace(3939): Unexpected value from nativeGetEnabledTags: 0
07-12 10:49:57.699: D/dalvikvm(3939): GC_FOR_ALLOC freed 68K, 7% free 2517K/2704K, paused 98ms, total 115ms
07-12 10:49:57.749: I/dalvikvm-heap(3939): Grow heap (frag case) to 5.697MB for 3279376-byte allocation
07-12 10:49:57.849: D/dalvikvm(3939): GC_FOR_ALLOC freed 1K, 4% free 5718K/5908K, paused 89ms, total 89ms
07-12 10:49:57.969: D/dalvikvm(3939): GC_CONCURRENT freed <1K, 4% free 5718K/5908K, paused 10ms+27ms, total 119ms
07-12 10:49:59.648: D/dalvikvm(3939): GC_FOR_ALLOC freed <1K, 4% free 5718K/5908K, paused 341ms, total 342ms
07-12 10:50:00.408: I/dalvikvm-heap(3939): Grow heap (frag case) to 12.732MB for 7378576-byte allocation
07-12 10:50:01.018: D/dalvikvm(3939): GC_CONCURRENT freed 0K, 2% free 12924K/13116K, paused 9ms+81ms, total 611ms
07-12 10:50:02.560: D/AndroidRuntime(3939): Shutting down VM
07-12 10:50:02.560: W/dalvikvm(3939): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
07-12 10:50:02.598: E/AndroidRuntime(3939): FATAL EXCEPTION: main
07-12 10:50:02.598: E/AndroidRuntime(3939): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.activity/com.application.activity.MainActivity}: java.lang.NullPointerException
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.os.Looper.loop(Looper.java:137)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread.main(ActivityThread.java:5039)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at java.lang.reflect.Method.invokeNative(Native Method)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at java.lang.reflect.Method.invoke(Method.java:511)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at dalvik.system.NativeStart.main(Native Method)
07-12 10:50:02.598: E/AndroidRuntime(3939): Caused by: java.lang.NullPointerException
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.net.Uri.withAppendedPath(Uri.java:2290)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at com.application.activity.MainActivity.putLinearLayout(MainActivity.java:56)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at com.application.activity.MainActivity.onCreate(MainActivity.java:31)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.Activity.performCreate(Activity.java:5104)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-12 10:50:02.598: E/AndroidRuntime(3939):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-12 10:50:02.598: E/AndroidRuntime(3939):  ... 11 more

Share this post


Link to post
Share on other sites

Un up à deux heures d'intervalle, c'est un coup à se faire dégommer son sujet, ça...

Je dis ça, je n'ai rien dit... siffle.gif

Share this post


Link to post
Share on other sites

il semblerait que ton erreur n'ai rien à voir avec la base de données.

A priori tu as récupéré ton path (/res/drawable/fish) mais cela ne correspond à rien dans ton appli

java.io.FileNotFoundException: /res/drawable/fish: open failed: ENOENT (No such file or directory)

=> perso je mets les images dont le path est obtenu dynamiquement dans l'arborescence assets

Edited by elmarco06

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.






×
×
  • Create New...