• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

request in SQLite

 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 une méthode pour récupérer l'@ de l'image, mais lorsque je compile, l'emulateur affihe des boutons mais sans image
voici la méthode :
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 "";
}

et au niveau de main activity :
ImageButton b1= new ImageButton(this);
image = db.getImage(i);
b1.setImageURI(Uri.parse(image));

le logcat affiche comme résultat :

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

Merci pour votre aide
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please provide an English translation of your post - this is an English-only web site, and posts in other languages that have no translation are generally deleted quickly.

Be sure to describe which is line 56 of the code, and which values you're passing to any methods in it - that seems to be (at least part of) the problem.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a SQLite database which contains two tables: tables for classes and tables for images that contain the adress of image
I want to load images stored in the database and used in a button, i just want to know how can i do it
 
author & internet detective
Posts: 41763
885
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not an English translation. That's an English summary. You need to translate everything in your first post except the code and log messages to English. If this does not happen, this thread will be deleted.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, i'm sorry
I created a SQLite database which contains two tables: tables for classes and tables for images that contain the adress of image
/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 ); " ;

I want to load images stored in the database and used in a button
So I created a method to retrieve the @ of the image, but when I compile the emulator display only the buttons but without image
here is the method:

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())
{
String strCatName = c.getString(c.getColumnIndex(COL_ADRESS_IMAGE ));
c.close();
database.close();
return strCatName;
}
else
{
return "";
}

at the main activity i wrote :

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

and here's the logcat result:
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

I need your help really, and i'm sorry another time
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Be sure to describe which is line 56 of the code, and which values you're passing to any methods in it - that seems to be (at least part of) the problem.

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the main activity :

LinearLayout Linear = (LinearLayout)findViewById(R.id.linearlayout2);
DataBase db = new DataBase(this);
String image;
for(int i=1;i<=number;i++)
{
LinearLayout L = new LinearLayout(this);
ImageButton b1= new ImageButton(this);
image = db.getImage(i);
b1.setImageURI(Uri.parse(image));

L.addView(b1);
Linear .addView(L);
}
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please i need your help, i'm stuck
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

Ulf Dittmer wrote:Be sure to describe which is line 56 of the code, and which values you're passing to any methods in it - that seems to be (at least part of) the problem.


In particular, make sure that all parameters have the values that you think they have. Don't just assume that they have - make sure that they do.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked all the values, it may be a problem with the address of image
For example one of the adress : "res/drawable/pizza.jpg"
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not asking for "all the values", I'm asking about the ones used in and around line 56 of your code. Did you notice that the stack trace specifically mentions that line number? You still haven't told us which line of code that is.

In order to make it easy for folks here to help you, you need to tell us as much information as possible. If we need to ask for every little detail, we'll probably lose interest. So: TellTheDetails
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here's the code :
public void putLinearLayout(double number)
{
LinearLayout Linear = (LinearLayout)findViewById(R.id.linearlayout2);
DataBase db = new DataBase(this);
String name;
String image = null;
int mButtonHeight = 70;//hauteur
int mButtonWidth = 120;//longueur
Button im = (Button)findViewById(R.id.button4);
Drawable d = Drawable.createFromPath("res/drawable/pizza.jpg");
im.setBackground(d);

for(int i=1;i<=number;i++)
{
LinearLayout L = new LinearLayout(this);//line 56
//L.setBackgroundColor(Color.WHITE);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //<--this line , is what you were missing
L.setLayoutParams(params); //<-- and then this

ImageButton b1= new ImageButton(this);
image = db.getImage(i);
b1.setImageURI(Uri.parse(image));
TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER);
tv.setTextColor(Color.BLUE);
name=db.getCategoryName(i);
tv.setText(name);
L.setOrientation(LinearLayout.VERTICAL);
b1.setMinimumWidth(mButtonWidth);
b1.setMinimumHeight(mButtonHeight);
L.addView(b1);
L.addView(tv);
Linear .addView(L);
}
thanks for your help
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a few problems. First:

Sarra Sakka wrote: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)


That comes from code like this:

Sarra Sakka wrote:


The drawables delivered to the phone are not packaged in a file/directory structure that you can navigate like that. They are put together as resources. You should get them from the resources via their resource ID:
One side benefit of this (perhaps the main reason for this...) is that you can package different drawables appropriate to different screen sizes and densities, and access them the same exact way (and let Android determine the best one to use). Read this tutorial on the Android developer's network.

But then the next exception you get is this:

Sarra Sakka wrote:: java.lang.RuntimeException: ...: java.lang.NullPointerException
...
: Caused by: java.lang.NullPointerException
: at android.net.Uri.withAppendedPath(Uri.java:2290)
: at com.application.activity.MainActivity.putLinearLayout(MainActivity.java:56)
: at com.application.activity.MainActivity.onCreate(MainActivity.java:31)

And you say your code is:

Sarra Sakka wrote:


From that, we know that the code goes from MainActivity.java line 31 (in your onCreate() method) to MainActivity.java line 56 (in your putLinearLayout() method). It then proceeds to android.net.Uri.withAppendedPath() which ends up with a null pointer exception. I have a hard time following how LinearLayout L = new LinearLayout(this); could lead to the android.net.Uri class, and get a null pointer exception there. Are you sure you are getting the line correct? If you are using Eclipse, when you press CTRL + L and type in 56 do you go to the line you have highlighted? If so, can you clean your application (under the Project menu) and run it again to make sure you are getting lines and errors relative to your current code?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, i want to thank you very much
here's again my code, I changed a little :



public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


DataBase db = new DataBase(this);
db.open();
double count = db.getCategoryNumber();
putLinearLayout(count);
db.close();

}

public void putLinearLayout(double number)
{
LinearLayout Linear = (LinearLayout)findViewById(R.id.linearlayout2);
DataBase db = new DataBase(this);
String name;
String image;

int mButtonHeight = 70;//hauteur
int mButtonWidth = 120;//longueur
// Button im = (Button)findViewById(R.id.button4);
for(int i=1;i<=number;i++)
{
LinearLayout L = new LinearLayout(this);
//L.setBackgroundColor(Color.WHITE);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //<--this line , is what you were missing
L.setLayoutParams(params); //<-- and then this

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

TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER);
tv.setTextColor(Color.BLUE);
name=db.getCategoryName(i);
tv.setText(name);
L.setOrientation(LinearLayout.VERTICAL);
b1.setMinimumWidth(mButtonWidth);
b1.setMinimumHeight(mButtonHeight);
L.addView(b1);
L.addView(tv);
Linear .addView(L);
}

}

}

and the method :
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())
{
String strCatName = c.getString(c.getColumnIndex(COL_ADRESS_IMAGE ));
c.close();
database.close();
return strCatName;
}
else
{
return "";
}

here's the logcat what it display :

07-12 22:35:19.924: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:19.924: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:20.174: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:20.194: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:21.194: D/dalvikvm(1016): GC_FOR_ALLOC freed 59K, 7% free 2517K/2692K, paused 40ms, total 43ms
07-12 22:35:21.224: I/dalvikvm-heap(1016): Grow heap (frag case) to 5.697MB for 3279376-byte allocation
07-12 22:35:21.294: D/dalvikvm(1016): GC_FOR_ALLOC freed 1K, 4% free 5718K/5896K, paused 60ms, total 60ms
07-12 22:35:21.384: D/dalvikvm(1016): GC_CONCURRENT freed <1K, 4% free 5718K/5896K, paused 5ms+6ms, total 89ms
07-12 22:35:21.976: D/dalvikvm(1016): GC_FOR_ALLOC freed <1K, 4% free 5718K/5896K, paused 36ms, total 36ms
07-12 22:35:22.054: I/dalvikvm-heap(1016): Grow heap (frag case) to 12.732MB for 7378576-byte allocation
07-12 22:35:22.314: D/dalvikvm(1016): GC_CONCURRENT freed 0K, 2% free 12923K/13104K, paused 181ms+7ms, total 261ms
07-12 22:35:23.035: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.035: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.116: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.175: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.375: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.395: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.395: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.475: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.475: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.515: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.515: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.535: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.535: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.565: D/gralloc_goldfish(1016): Emulator without GPU emulation detected.
07-12 22:35:23.755: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.775: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.085: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.195: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.195: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.315: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.335: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.345: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.355: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.415: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.415: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.756: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.765: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.985: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.725: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.725: I/Choreographer(1016): Skipped 448 frames! The application may be doing too much work on its main thread.
07-12 22:35:31.735: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.825: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.886: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.005: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.025: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.045: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.125: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.125: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.205: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.205: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.225: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.225: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.565: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.615: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.674: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.674: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.884: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.906: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:34.544: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.684: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.954: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.995: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:48.114: D/dalvikvm(1118): GC_FOR_ALLOC freed 62K, 7% free 2517K/2696K, paused 88ms, total 91ms
07-12 22:50:48.154: I/dalvikvm-heap(1118): Grow heap (frag case) to 5.697MB for 3279376-byte allocation
07-12 22:50:48.225: D/dalvikvm(1118): GC_FOR_ALLOC freed 1K, 4% free 5718K/5900K, paused 64ms, total 64ms
07-12 22:50:48.294: D/dalvikvm(1118): GC_CONCURRENT freed <1K, 4% free 5718K/5900K, paused 10ms+5ms, total 76ms
07-12 22:50:48.864: D/dalvikvm(1118): GC_FOR_ALLOC freed <1K, 4% free 5718K/5900K, paused 34ms, total 34ms
07-12 22:50:48.934: I/dalvikvm-heap(1118): Grow heap (frag case) to 12.732MB for 7378576-byte allocation
07-12 22:50:49.054: D/dalvikvm(1118): GC_CONCURRENT freed 0K, 2% free 12923K/13108K, paused 23ms+39ms, total 120ms
07-12 22:50:49.454: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/pizza
07-12 22:50:49.454: E/BitmapFactory(1118): : open failed: ENOENT (No such file or directory)
07-12 22:50:49.454: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/pizza
07-12 22:50:49.564: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/salade: open failed: ENOENT (No such file or directory)
07-12 22:50:49.564: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/salade
07-12 22:50:49.664: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/fish: open failed: ENOENT (No such file or directory)
07-12 22:50:49.664: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/fish
07-12 22:50:49.764: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/boissons: open failed: ENOENT (No such file or directory)
07-12 22:50:49.764: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/boissons
07-12 22:50:49.864: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.864: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.914: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.995: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.115: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.144: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.174: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.294: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.294: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.354: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.354: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.364: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.374: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.414: D/gralloc_goldfish(1118): Emulator without GPU emulation detected.
07-12 22:50:50.554: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.654: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0

07-12 22:35:19.924: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:19.924: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:20.174: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:20.194: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:21.194: D/dalvikvm(1016): GC_FOR_ALLOC freed 59K, 7% free 2517K/2692K, paused 40ms, total 43ms
07-12 22:35:21.224: I/dalvikvm-heap(1016): Grow heap (frag case) to 5.697MB for 3279376-byte allocation
07-12 22:35:21.294: D/dalvikvm(1016): GC_FOR_ALLOC freed 1K, 4% free 5718K/5896K, paused 60ms, total 60ms
07-12 22:35:21.384: D/dalvikvm(1016): GC_CONCURRENT freed <1K, 4% free 5718K/5896K, paused 5ms+6ms, total 89ms
07-12 22:35:21.976: D/dalvikvm(1016): GC_FOR_ALLOC freed <1K, 4% free 5718K/5896K, paused 36ms, total 36ms
07-12 22:35:22.054: I/dalvikvm-heap(1016): Grow heap (frag case) to 12.732MB for 7378576-byte allocation
07-12 22:35:22.314: D/dalvikvm(1016): GC_CONCURRENT freed 0K, 2% free 12923K/13104K, paused 181ms+7ms, total 261ms
07-12 22:35:23.035: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.035: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.116: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.175: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.375: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.395: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.395: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.475: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.475: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.515: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.515: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.535: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.535: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.565: D/gralloc_goldfish(1016): Emulator without GPU emulation detected.
07-12 22:35:23.755: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:23.775: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.085: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.115: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.195: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.195: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.315: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.335: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.345: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.355: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.415: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:26.415: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.756: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.765: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:29.985: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.725: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.725: I/Choreographer(1016): Skipped 448 frames! The application may be doing too much work on its main thread.
07-12 22:35:31.735: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.825: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:31.886: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.005: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.025: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.045: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.125: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.125: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.205: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.205: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.225: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.225: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.565: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:35:32.615: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.674: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.674: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.884: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:31.906: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:34.544: W/Trace(1016): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.684: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.954: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:46.995: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:48.114: D/dalvikvm(1118): GC_FOR_ALLOC freed 62K, 7% free 2517K/2696K, paused 88ms, total 91ms
07-12 22:50:48.154: I/dalvikvm-heap(1118): Grow heap (frag case) to 5.697MB for 3279376-byte allocation
07-12 22:50:48.225: D/dalvikvm(1118): GC_FOR_ALLOC freed 1K, 4% free 5718K/5900K, paused 64ms, total 64ms
07-12 22:50:48.294: D/dalvikvm(1118): GC_CONCURRENT freed <1K, 4% free 5718K/5900K, paused 10ms+5ms, total 76ms
07-12 22:50:48.864: D/dalvikvm(1118): GC_FOR_ALLOC freed <1K, 4% free 5718K/5900K, paused 34ms, total 34ms
07-12 22:50:48.934: I/dalvikvm-heap(1118): Grow heap (frag case) to 12.732MB for 7378576-byte allocation
07-12 22:50:49.054: D/dalvikvm(1118): GC_CONCURRENT freed 0K, 2% free 12923K/13108K, paused 23ms+39ms, total 120ms
07-12 22:50:49.454: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/pizza
07-12 22:50:49.454: E/BitmapFactory(1118): : open failed: ENOENT (No such file or directory)
07-12 22:50:49.454: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/pizza
07-12 22:50:49.564: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/salade: open failed: ENOENT (No such file or directory)
07-12 22:50:49.564: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/salade
07-12 22:50:49.664: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/fish: open failed: ENOENT (No such file or directory)
07-12 22:50:49.664: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/fish
07-12 22:50:49.764: E/BitmapFactory(1118): Unable to decode stream: java.io.FileNotFoundException: /res/drawable/boissons: open failed: ENOENT (No such file or directory)
07-12 22:50:49.764: I/System.out(1118): resolveUri failed on bad bitmap uri: res/drawable/boissons
07-12 22:50:49.864: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.864: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.914: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:49.995: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.115: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.144: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.174: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.294: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.294: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.354: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.354: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.364: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.374: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.414: D/gralloc_goldfish(1118): Emulator without GPU emulation detected.
07-12 22:50:50.554: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0
07-12 22:50:50.654: W/Trace(1118): Unexpected value from nativeGetEnabledTags: 0

as I already said, I store images in a table with their address, it seems that the problem is due to these address !!


 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:...as I already said, I store images in a table with their address, it seems that the problem is due to these address !!


Yes, that is right. If you package images in the res/drawables folder they will not be accessible via URIs because they do not exist in the file system, as I already stated. You should NOT be referencing them that way. You should be referencing them by the resource ID. The lookup would be much faster is you used R.drawables.pizza to get the resource ID (like I showed in my previous post.

I think this is a problem with your strategy. Why do you want to store the URIs in the database? Why go through the trouble of a DB lookup instead of a constant field reference?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do research and I found that the type of image in SQLite is BLOB or TEXT types with TEXT contains the @ of image.
I want to store the url in my database because the images will display dynamically, ie is the following the application displays different pictures
you understand me!! please help me to solve this problem i must do it and i'm stuck
according to you, how do I solve this problem to?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'am waiting for your answer
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PatienceIsAVirtue. You do realize that -according to his profile page- Steve lives in a timezone where most likely he would now be sleeping? And that's assuming that he would be visiting a tech web site on the weekend - a big if.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mmmm, ok
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I mentioned before, you can't access the images by URI if they are stored in the resource folder. You can access them by their resource ID. I realize you want to do things dynamically, but the way you are doing it doesn't make sense when you know how things are structured. Here are some suggestions:

1) Store the resource IDs for all the images you want into an Array or List. Then when you want to access them dynamically, get them out of the array/list:


2) If you really want to use the database, store the images in the database as blobs. I personally wouldn't do this.

3) If you really want to use the database but don't want to store the images as blobs, store the image resource ids in the DB.

4) If you really want to access the images by URI instead of resource ID, then store the images someplace where they do not get compiled. The best place is probably the /assets folder (not the /res folder, as they get compiled). Then use AssetManager to look them up. For example, you might do:
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Steve
I will choose the fourth suggestion,
So i must replace all my image in the assets folder,
i will try and I'll informe you what gave me ;)
thanks another time
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve! some thing else
How can i put this image in the button
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:Steve! some thing else
How can i put this image in the button


Have you had a look at the Android API yet? Here it is: http://developer.android.com/reference/packages.html
It is a great resource for when what you need is to look up a method. Find the Button class and see how you might use a drawable with it.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i do this method

3) If you really want to use the database but don't want to store the images as blobs, store the image resource ids in the DB.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First: Resource IDs are integers, so you have to change the column type of the table from TEXT to INTEGER.

Second: Resource IDs are referenced by their constants created in the R class (which is auto-generated for you). The resource ID for a file named "/res/drawable/pizza.jpg" can be referenced as R.drawable.pizza

Third: When you build your database table, you put the value of the resource ID instead of the URI, as you had been using.

Fourth: When you read the info from the database, read an INTEGER instead of TEXT.

Fifth: To create the Drawable, use the methods I told you about in previous posts.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's mean, i must replaced forexample res / drawable / pizza by R.drawable.pizza in the table of image !!!
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:That's mean, i must replaced forexample res / drawable / pizza by R.drawable.pizza in the table of image !!!


Yes, but the table definition must be defined to use Integers as that column's datatype, not Text. Because if you define it as Text then you could get errors comparing values, or pulling values out.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks
i'll try it
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then, how can i load this image
can you explain me more with a simple code or request
thank in advance Steve
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:then, how can i load this image
can you explain me more with a simple code or request
thank in advance Steve


You should have all the code you need:

- You have code which creates the table. I know you have this code because you are currently using the database. That will need to be modified.
- You have code which gets the resource id. I have shown multiple examples.
- You have code for putting data in the database. I know you have this code because you are currently using the database.
- You have code for getting data from the database. Diddo on how I know.
- You have code for getting a Drawable from the resource ID. I have shown you that multiple times. Including in this thread and in the thread where I showed you how to use the GridView

So, you have all the pieces you need. Why don't you give putting it together a shot.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, I bother you a lot
I want again,the code to how get the ID resource
Thanks in avance
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:I'm sorry, I bother you a lot
I want again,the code to how get the ID resource and how to get data from database
Thanks in avance

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I change the type of image_adress to integer how you told me,
I modify this method :

then in the main activity :


but when i compile it, it doesn't work :
 
Marshal
Posts: 27902
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're getting that "no such column" message several times. I would check it out and fix the problem it's pointing to.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's work now
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic