Xamarin Android Assets.Open 引发 FileNotFound 异常 [英] Xamarin Android Assets.Open throws FileNotFound exception

查看:45
本文介绍了Xamarin Android Assets.Open 引发 FileNotFound 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来很简单,但不知道为什么我不能使用Assets.open方法而不会得到FileNotFound异常.

It seems to be very easy, but don't know why I can't use Assets.open method without getting FileNotFound exception.

我遵循了 xamrain.com 中的一个示例http://docs.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_6_-_using_android_assets/

I followed an example in xamrain.com http://docs.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_6_-_using_android_assets/

仍然没有让它工作.

我在Assets文件夹下添加了一个txt文件将构建操作设置为AndroidAsset"我还尝试将 COpy 的输出目录设置为始终复制"和不复制".

I added a txt file under Assets folder Set the Build Action to "AndroidAsset" I tried with also setting COpy to Output Diretory to "Always Copy" and "Do not Copy".

无论什么组合,我总是得到 FileNotFound 异常.

No matter what the combination, I always get FileNotFound exception.

看起来很多开发人员也看到了这个问题,但我没有看到我可以尝试的答案.感谢有人能阐明这个简单的主题.

Looked like many of fellow developers also see the problem and I don't see the answer that I can try. Appreciate if someone could shed a light on this easy subject.

提前致谢

推荐答案

首先,如果没有看到您的代码,就不可能看到您可能遗漏的任何错误.很容易遗漏文件名问题或其他可能不那么明显的问题.

Firstly, without seeing your code, it's impossible to see any mistakes you may have missed. It's easy to miss a filename issue, or other problem that may not be so obvious.

虽然是推测性的,但我会试着给你一些提示.

Speculatively though, I will try to give you some pointers.

复制到输出目录"设置对于 Android 资源并不重要.AndroidAsset 的构建操作将确保该文件包含在应用程序包中,允许您使用 Assets.Open() 加载它.

The 'Copy to Output Directory' setting is not important for Android resources. The build action of AndroidAsset will ensure that the file is included in the app package, allowing you to load it using Assets.Open().

要确认这一点,请在 bin/debug 或 bin/release 文件夹中查找已编译的 .apk 文件..apk 文件只是一个存档,因此您可以使用 winrar 或 7-zip 打开它,或者将其重命名为 .zip,Windows 将打开它.

To confirm this, have a look for the compiled .apk file in the bin/debug or bin/release folder. The .apk file is simply an archive, so you can open it up with with winrar, or 7-zip, or rename it to .zip and windows will open it.

如果文件在 assets 文件夹中,那么您的代码可能有问题.你应该在你的问题中发布它.如果该文件不存在,请尝试清理您的项目,或删除 bin 文件夹以强制重新构建并重新打包.

If the file is in the assets folder, then there is probably a problem with your code. You should post it in your question. If the file isn't there, try cleaning your project, or deleting the bin folder to force a fresh build and re-package.

这篇关于Xamarin Android Assets.Open 引发 FileNotFound 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆