J'ai écrit une application Android et jusqu'à présent, il fonctionne parfaitement, sauf sur un seul téléphone. C'est le téléphone exact que j'ai avec 2.2 sur les deux téléphones et le mien fonctionne parfaitement. L'autre téléphone est en train de fermer de force tout le temps, mais uniquement lors de l'ouverture d'une activité qui interroge ma base de données d'images et tente d'afficher une galerie. Chaque activité se bloque au même endroit, les viewimages. Au début je pensais que c'était l'intention qui le faisait mais l'une des activités n'a pas l'intention, elle ouvre les images en dessous de la galerie. Cela fonctionne sur l'émulateur, sur mon droïde de moto et sur quelques autres droïdes différents. Voici le code pour la galerie et mon décodeur bitmap. L'erreur est en dessous de cela. Si n'importe qui peut voir n'importe quoi qui le ferait s'écraser j'apprécierais vraiment l'aide.Android java.lang.RuntimeException: Impossible de démarrer l'activité ComponentInfo
public void viewimages() {
String [] proj={ImageProvider._ID, ImageProvider.IMAGE, ImageProvider.TABLENAME,
ImageProvider.ITEMID, ImageProvider.IMAGEDATE};
cursor = managedQuery(ImageProvider.CONTENT_URI,
proj,
ImageProvider.TABLENAME + "=" + "'" + Tablename + "'"
+ " and " + ImageProvider.ITEMID + "=" + "'" + ID + "'",
null,
ImageProvider.IMAGEDATE);
Ligne 182 -> column_index = cursor.getColumnIndex (ImageProvider._ID);
g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
cursor.moveToPosition(position);
ImageID = cursor.getLong(column_index);
Intent i = new Intent(LivestockDetails.this, ImageViewer.class);
i.putExtra("id", ImageID);
startActivity(i);
}
});
}
private Bitmap decodeFile(String file){
Bitmap b = null;
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, o);
int scale = 1;
if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
scale = 2^(int) Math.ceil(Math.log(IMAGE_MAX_SIZE/(double) Math.max(o.outHeight, o.outWidth))/Math.log(0.5));
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
b = BitmapFactory.decodeFile(file, o2);
return b;
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
if (convertView == null) {
String [] proj={ImageProvider._ID, ImageProvider.IMAGE, ImageProvider.TABLENAME,
ImageProvider.ITEMID, ImageProvider.IMAGEDATE};
cursor = managedQuery(ImageProvider.CONTENT_URI,
proj,
ImageProvider.TABLENAME + "=" + "'" + Tablename + "'"
+ " and " + ImageProvider.ITEMID + "=" + "'" + ID + "'",
null,
ImageProvider.IMAGEDATE + " DESC");
column_path = cursor.getColumnIndex(ImageProvider.IMAGE);
column_index = cursor.getColumnIndex(ImageProvider._ID);
cursor.moveToPosition(position);
String filename = cursor.getString(column_path);
java.io.File file = new java.io.File(filename);
if(!file.exists()) {
ImageID = cursor.getLong(column_index);
getContentResolver().delete(ImageProvider.CONTENT_URI,
ImageProvider._ID + "=" + ImageID, null);
Toast.makeText(LivestockDetails.this,
"There are missing images. They have been removed from the database." ,
Toast.LENGTH_LONG).show();
viewimages();
}
else {
Bitmap bitmapOrg = null;
bitmapOrg = decodeFile(filename);
Matrix matrix = new Matrix();
matrix.postScale(scale,scale);
resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
bitmapOrg.getWidth(), bitmapOrg.getHeight(), matrix, true);
Drawable delete = i.getDrawable();
if(delete!= null) {
((BitmapDrawable)i.getDrawable()).getBitmap().recycle();
i.setImageBitmap(resizedBitmap);
}
else {
i.setImageBitmap(resizedBitmap);
}
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(240, 180));
i.setBackgroundResource(mGalleryItemBackground);
}
}
return i;
}
}
Voici l'erreur
java.lang.RuntimeException: Unable to start activity ComponentInfo{myaquarium.logger/myaquarium.logger.LivestockDetails}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at myaquarium.logger.LivestockDetails.viewimages(LivestockDetails.java:182)
at myaquarium.logger.LivestockDetails.onCreate(LivestockDetails.java:71)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Quelle ligne est la ligne 182 de LivestockDetails? –
Selon Eclipse, il s'agit de: \t \t column_index = cursor.getColumnIndex (ImageProvider._ID); – Opy
En fait, c'est la ligne, il se ferme à l'autre page, j'ai un rapport d'erreur pour aussi. Gardez à l'esprit que cela fonctionne très bien sur plusieurs téléphones et que celui sur lequel il se bloque est identique au mien qui fonctionne bien. – Opy