java.io.FileNotFoundException: open failed: ENOENT (No such file or directory

java.io.FileNotFoundException: open failed: ENOENT (No such file or directory

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)
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.

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 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);
}

[1] [2] Next

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright