尝试在gridview中查看已保存的摄像机图片时收到警告

时间:2013-03-10 12:10:52

标签: android gridview android-camera filenotfoundexception

我打算在我的项目中使用相机/图库。这是我首先拍摄的照片并将其保存在我的文件夹中(假设pictureworld)并将图像库保存在本地数据库中。然后当我试图让图片在gridview中显示时,我收到一条警告信息。在gridview中没有图片,但它可以查看图片名称。我已经检查过它正在创建图片,而且本地数据库中的uri也是正确的。我想在我尝试使用图库保存图片时添加它...这没有问题。我使用相同的适配器来查看已保存的图库和相机图片。我在这附上警告:

03-10 17:48:11.367: W/System.err(522):  at libcore.io.IoBridge.open(IoBridge.java:406)
03-10 17:48:11.367: W/System.err(522):  at java.io.FileInputStream.<init>(FileInputStream.java:78)
03-10 17:48:11.367: W/System.err(522):  at java.io.FileInputStream.<init>(FileInputStream.java:105)
03-10 17:48:11.367: W/System.err(522):  at android.content.ContentResolver.openInputStream(ContentResolver.java:369)
03-10 17:48:11.367: W/System.err(522):  at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:705)
03-10 17:48:11.367: W/System.err(522):  at hr.s2is.ischool.admin.adapter.CommunityUserAdapter.getView(CommunityUserAdapter.java:71)
03-10 17:48:11.367: W/System.err(522):  at android.widget.AbsListView.obtainView(AbsListView.java:2033)
03-10 17:48:11.367: W/System.err(522):  at android.widget.GridView.makeAndAddView(GridView.java:1323)
03-10 17:48:11.377: W/System.err(522):  at android.widget.GridView.makeRow(GridView.java:328)
03-10 17:48:11.377: W/System.err(522):  at android.widget.GridView.fillDown(GridView.java:281)
03-10 17:48:11.377: W/System.err(522):  at android.widget.GridView.fillFromTop(GridView.java:403)
03-10 17:48:11.377: W/System.err(522):  at android.widget.GridView.layoutChildren(GridView.java:1215)
03-10 17:48:11.377: W/System.err(522):  at android.widget.AbsListView.onLayout(AbsListView.java:1863)
03-10 17:48:11.377: W/System.err(522):  at android.view.View.layout(View.java:11278)
03-10 17:48:11.377: W/System.err(522):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.377: W/System.err(522):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
03-10 17:48:11.387: W/System.err(522):  at android.view.View.layout(View.java:11278)
03-10 17:48:11.387: W/System.err(522):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.387: W/System.err(522):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-10 17:48:11.387: W/System.err(522):  at android.view.View.layout(View.java:11278)
03-10 17:48:11.387: W/System.err(522):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.387: W/System.err(522):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
03-10 17:48:11.397: W/System.err(522):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
03-10 17:48:11.397: W/System.err(522):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
03-10 17:48:11.397: W/System.err(522):  at android.view.View.layout(View.java:11278)
03-10 17:48:11.397: W/System.err(522):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.397: W/System.err(522):  at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
03-10 17:48:11.397: W/System.err(522):  at android.view.View.layout(View.java:11278)
03-10 17:48:11.397: W/System.err(522):  at android.view.ViewGroup.layout(ViewGroup.java:4224)
03-10 17:48:11.407: W/System.err(522):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
03-10 17:48:11.407: W/System.err(522):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
03-10 17:48:11.407: W/System.err(522):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-10 17:48:11.407: W/System.err(522):  at android.os.Looper.loop(Looper.java:137)
03-10 17:48:11.407: W/System.err(522):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-10 17:48:11.407: W/System.err(522):  at java.lang.reflect.Method.invokeNative(Native Method)
03-10 17:48:11.417: W/System.err(522):  at java.lang.reflect.Method.invoke(Method.java:511)
03-10 17:48:11.417: W/System.err(522):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-10 17:48:11.417: W/System.err(522):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-10 17:48:11.417: W/System.err(522):  at dalvik.system.NativeStart.main(Native Method)
03-10 17:48:11.417: W/System.err(522): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
03-10 17:48:11.427: W/System.err(522):  at libcore.io.Posix.open(Native Method)
03-10 17:48:11.427: W/System.err(522):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
03-10 17:48:11.427: W/System.err(522):  at libcore.io.IoBridge.open(IoBridge.java:390)

2 个答案:

答案 0 :(得分:0)

您是否已获得阅读本地存储空间的许可?您应该检查是否在Android Manifest中声明了有关写入和读取内部存储的任何权限。

答案 1 :(得分:0)

你是否添加了权限

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

还有一件事:

使用sdk,您无法写入内部存储的根目录。这会导致你的错误。尝试这样的事情

final File dir = new File(context.getFilesDir() + "/nfs/guille/groce/users/nicholsk/workspace3/SQLTest");
dir.mkdirs(); //create folders where write files
final File file = new File(dir, "BlockForTest.txt");