我正在尝试使对话框显示捕获的照片库,但是在此上运行时,gv.setAdapter(new EOrderGalleryAdapter(getApplicationContext(), data));
会发生 Null Exception。
是否有任何关于使用默认打开位于外部 SD 卡中的文件的照片的提示或教程 - 图库或其他?
以下是我的代码
final Dialog dialog = new Dialog(getBaseContext());
//remove the default title if you want to
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//here is where we inflate our custom xml containing a gridview
dialog.setContentView(R.layout.gallery);
String sdCardRootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString()+"/TVB_PV_photo";
File rootFolder = new File(sdCardRootPath);
File[] picFiles = rootFolder.listFiles();
ArrayList<Bitmap> data = new ArrayList<Bitmap>();
for (File pic:picFiles) {
//Bitmap b= BitmapFactory.decodeFile(pic.getAbsolutePath());
Bitmap b = decodeFile(pic,4);
data.add(b);
}
GridView gv = (GridView) findViewById(R.id.grid_view);
gv.setAdapter(new EOrderGalleryAdapter(getApplicationContext(), data));
gv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(),
"photo" + (position + 1) + " selected",
Toast.LENGTH_SHORT).show();
}});
日志猫
06-21 10:19:50.946: E/AndroidRuntime(3925): at android.view.View$1.onClick(View.java:3125)
06-21 10:19:50.946: E/AndroidRuntime(3925): ... 11 more
06-21 10:19:50.946: E/AndroidRuntime(3925): Caused by: java.lang.NullPointerException
06-21 10:19:50.946: E/AndroidRuntime(3925): at atvpv.test.OrderSystem1.EOSCustPayment.onCreateDialog(EOSCustPayment.java:352)
06-21 10:19:50.946: E/AndroidRuntime(3925): at android.app.Activity.onCreateDialog(Activity.java:2828)
06-21 10:19:50.946: E/AndroidRuntime(3925): at android.app.Activity.createDialog(Activity.java:944)
06-21 10:19:50.946: E/AndroidRuntime(3925): at android.app.Activity.showDialog(Activity.java:2921)
06-21 10:19:50.946: E/AndroidRuntime(3925): at android.app.Activity.showDialog(Activity.java:2880)
06-21 10:19:50.946: E/AndroidRuntime(3925): at atvpv.test.OrderSystem1.EOSCustPayment.buttonGallery(EOSCustPayment.java:421)