gpt4 book ai didi

安卓java.lang.RuntimeException : Unable to start activity ComponentInfo

转载 作者:行者123 更新时间:2023-11-30 04:48:47 25 4
gpt4 key购买 nike

我写了一个 Android 应用程序,到目前为止它运行完美,除了在一部手机上。这正是我在两部手机上都配备 2.2 的手机,而且我的手机运行完美。另一部手机一直强制关闭,但只有在打开查询我的图像数据库并尝试显示画廊的 Activity 时才会关闭。每个 Activity 都在同一个地方崩溃,viewimages。起初我以为这是这样做的 Intent ,但其中一项 Activity 没有 Intent ,它打开了画廊下方的图像。这适用于模拟器、我的摩托机器人和其他一些不同的机器人。这是画廊和我的位图解码器的代码。错误低于那个。如果有人能看到任何会使它崩溃的东西,我将非常感谢您的帮助。

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

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

这里是错误

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

最佳答案

我终于明白了。我的内容提供商搞砸了。我有两个应用程序,一个用于测试,一个用于发布。我有用于发布的内容提供者指向我的测试应用程序,因此在模拟器中它工作正常,因为内容提供者在那里,但是当有人购买我的应用程序时,内容提供者丢失了。如果只有错误报告提供更多信息。当我通过卸载所有内容然后仅安装主应用程序在我的模拟器上复制它时,logcat 告诉我找不到内容提供者。这就是为什么它每次都在光标上崩溃。

关于安卓java.lang.RuntimeException : Unable to start activity ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4128493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com