对于可能发布与许多其他问题类似的问题,我感到很抱歉,但我找不到解决方案或找到与发生此错误的情况类似的情况。我整个星期都在谷歌搜索和搜索,试图找到这个问题的答案,但到目前为止还没有运气。我对android还很陌生,所以如果很明显,这可能就是原因!
这些是导致错误的步骤:
该应用程序使用相机拍照
然后将此图像存储在 SDCard 上的文件夹
中制作此文件的副本并压缩到每张图像 50-100kb(这是我要显示的内容)
然后存储加载活动(onResume 我这样做)时, sqlite 数据库中图像的初始大小和文件名
如果数据库中有任何文件名,它会获取文件名并显示图像 - 这就是错误所在.
if(c.getCount() > 0) {
String[] cols = new String[] {DBAdapter.FILENAME,DBAdapter.DATETIME};
int[] values = new int[] {R.id.thumbnail,R.id.datetime_stamp};
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.image_listview, c, cols, values, 0);
ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(cursorAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
String row = c.getString(c.getColumnIndexOrThrow(DBAdapter.KEY_ID)); // row ID from transactions
Toast.makeText(getBaseContext(), row, Toast.LENGTH_SHORT).show();
}
});
}
我显然错过了一些东西,但这只是让我发疯!
如果有任何帮助,我得到的错误是:
06-13 22:17:25.269: E/AndroidRuntime(24153): FATAL EXCEPTION: main
06-13 22:17:25.269: E/AndroidRuntime(24153): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:511)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:325)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:350)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:831)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ImageView.resolveUri(ImageView.java:573)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ImageView.setImageURI(ImageView.java:350)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.support.v4.widget.SimpleCursorAdapter.setViewImage(SimpleCursorAdapter.java:197)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.support.v4.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:143)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.AbsListView.obtainView(AbsListView.java:1451)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ListView.makeAndAddView(ListView.java:1786)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ListView.fillDown(ListView.java:705)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ListView.fillGap(ListView.java:676)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3579)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2294)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.widget.ListView.onTouchEvent(ListView.java:3493)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.View.dispatchTouchEvent(View.java:3935)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:934)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:973)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:973)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:973)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:973)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:973)
06-13 22:17:25.269: E/AndroidRuntime(24153): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1741)
06-13 22:17:25.269: E/AndroidRuntime(24153): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1172)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.app.Activity.dispatchTouchEvent(Activity.java:2135)
06-13 22:17:25.269: E/AndroidRuntime(24153): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1725)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2241)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.view.ViewRoot.handleMessage(ViewRoot.java:1925)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.os.Handler.dispatchMessage(Handler.java:130)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.os.Looper.loop(SourceFile:351)
06-13 22:17:25.269: E/AndroidRuntime(24153): at android.app.ActivityThread.main(ActivityThread.java:3814)
06-13 22:17:25.269: E/AndroidRuntime(24153): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 22:17:25.269: E/AndroidRuntime(24153): at java.lang.reflect.Method.invoke(Method.java:538)
06-13 22:17:25.269: E/AndroidRuntime(24153): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
06-13 22:17:25.269: E/AndroidRuntime(24153): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
06-13 22:17:25.269: E/AndroidRuntime(24153): at dalvik.system.NativeStart.main(Native Method)
提前感谢您的帮助。