そのため、ユーザーが写真を撮ってローカルに保存できるアプリケーションがあります。画像名は、後で参照して写真を呼び出すために、SQLite データベースに保存されます。現在、ビットマップ画像をイメージビューに設定する問題を追跡しました。これが私のコードです:
private void displayListView() {
// TODO Auto-generated method stub
Cursor cursor = info.getListData();
String[] listViewColumns = new String[] { Database.KEY_BREWNAME, Database.KEY_BREWERY, Database.KEY_RATING,
Database.KEY_DATEIMAGENAME, };
int[] dataToListView = new int[] { R.id.tvBrewName, R.id.tvBrewery, R.id.tvRating, R.id.ivThumb, };
dataAdapter = new SimpleCursorAdapter(this, R.layout.entrymain, cursor, listViewColumns, dataToListView, 0);
ViewBinder viewBinder = new ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
ImageView image = (ImageView)view;
Log.w(TAG, "******************List Image loaded == " + columnIndex + " **********************");
try {
FileInputStream fis = openFileInput(cursor.getString(columnIndex));
fis.close();
Log.w(TAG, "******************List Image loaded == fis.close **********************");
image.setImageBitmap(BitmapFactory.decodeStream(fis));
Log.w(TAG, "******************List Image loaded == setimage success **********************");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
};
};
ImageView image = (ImageView)findViewById(R.id.ivThumb);
viewBinder.setViewValue(image, cursor, cursor.getColumnIndex("date_image_name"));
dataAdapter.setViewBinder(viewBinder);
listview.setAdapter(dataAdapter);
コードは ViewBinder なしで問題なく動作し、log.w を使用して問題を image.setImageBitmap(BitmapFactory.decodeStream(fis)) まで追跡しましたが、なぜ画像が設定されないのかよくわかりません。このコードを他の場所で使用して大成功を収めました。設定されない理由についてのアイデアは、 java.io.IOException: read failed: EBADF (Bad file number) と関係があることがわかりますが、どうすればこれを修正できますか? 少し早いですがお礼を!
これが私のエラーログの一部です:
03-18 10:44:16.281: D/ActivityThread(19380): setTargetHeapUtilization:0.25
03-18 10:44:16.281: D/ActivityThread(19380): setTargetHeapIdealFree:8388608
03-18 10:44:16.281: D/ActivityThread(19380): setTargetHeapConcurrentStart:2097152
03-18 10:44:16.782: I/Adreno200-EGLSUB(19380): <ConfigWindowMatch:2087>: Format RGBA_8888.
03-18 10:44:16.792: E/(19380): <s3dReadConfigFile:75>: Can't open file for reading
03-18 10:44:16.792: E/(19380): <s3dReadConfigFile:75>: Can't open file for reading
03-18 10:44:17.112: D/AbsListView(19380): Get MotionRecognitionManager
03-18 10:44:17.152: W/Start(19380): ******************List Image loaded == 4 **********************
03-18 10:44:17.162: W/Start(19380): ******************List Image loaded == fis.close **********************
03-18 10:44:17.162: W/System.err(19380): java.io.IOException: read failed: EBADF (Bad file number)
03-18 10:44:17.172: W/System.err(19380): at libcore.io.IoBridge.read(IoBridge.java:442)
03-18 10:44:17.172: W/System.err(19380): at java.io.FileInputStream.read(FileInputStream.java:179)
03-18 10:44:17.172: W/System.err(19380): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:168)
03-18 10:44:17.172: W/System.err(19380): at java.io.BufferedInputStream.read(BufferedInputStream.java:309)
03-18 10:44:17.172: W/System.err(19380): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
03-18 10:44:17.172: W/System.err(19380): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:619)
03-18 10:44:17.172: W/System.err(19380): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:691)
03-18 10:44:17.172: W/System.err(19380): at com.ex.beerlog.Start$1.setViewValue(Start.java:78)
03-18 10:44:17.172: W/System.err(19380): at com.ex.beerlog.Start.displayListView(Start.java:91)
03-18 10:44:17.172: W/System.err(19380): at com.ex.beerlog.Start.onCreate(Start.java:56)
03-18 10:44:17.172: W/System.err(19380): at android.app.Activity.performCreate(Activity.java:5048)
03-18 10:44:17.172: W/System.err(19380): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-18 10:44:17.172: W/System.err(19380): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
03-18 10:44:17.172: W/System.err(19380): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
03-18 10:44:17.182: W/System.err(19380): at android.app.ActivityThread.access$700(ActivityThread.java:139)
03-18 10:44:17.182: W/System.err(19380): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
03-18 10:44:17.182: W/System.err(19380): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 10:44:17.182: W/System.err(19380): at android.os.Looper.loop(Looper.java:137)
03-18 10:44:17.182: W/System.err(19380): at android.app.ActivityThread.main(ActivityThread.java:4918)
03-18 10:44:17.182: W/System.err(19380): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 10:44:17.182: W/System.err(19380): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 10:44:17.182: W/System.err(19380): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
03-18 10:44:17.182: W/System.err(19380): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
03-18 10:44:17.182: W/System.err(19380): at dalvik.system.NativeStart.main(Native Method)
03-18 10:44:17.182: W/System.err(19380): Caused by: libcore.io.ErrnoException: read failed: EBADF (Bad file number)
03-18 10:44:17.182: W/System.err(19380): at libcore.io.Posix.readBytes(Native Method)
03-18 10:44:17.182: W/System.err(19380): at libcore.io.Posix.read(Posix.java:118)
03-18 10:44:17.182: W/System.err(19380): at libcore.io.BlockGuardOs.read(BlockGuardOs.java:149)
03-18 10:44:17.182: W/System.err(19380): at libcore.io.IoBridge.read(IoBridge.java:432)
03-18 10:44:17.182: W/System.err(19380): ... 23 more