- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
基于 1.6 SDK4
InputStream is = Resources.getSystem().openRawResource(R.raw.vortexrules);
这条线给我带来了无尽的麻烦......
我的 R.java 显示:
public static final class raw {
public static final int vortexrules=0x7f040000;
这告诉我编译器正在识别文本文件和文件夹并将它们设置为资源。
当我运行上面的代码时,试图将 InputStream 设置为我得到的文本文件:
07-31 01:53:58.839: ERROR/AndroidRuntime(19573): Uncaught handler: thread main exiting due to uncaught exception07-31 01:53:58.947: ERROR/AndroidRuntime(19573): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vortex.rules/com.vortex.rules.MainWindow}: android.content.res.Resources$NotFoundException: Resource ID #0x7f04000007-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2460)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread.access$2300(ActivityThread.java:119)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1837)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.os.Handler.dispatchMessage(Handler.java:99)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.os.Looper.loop(Looper.java:123)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread.main(ActivityThread.java:4246)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at java.lang.reflect.Method.invokeNative(Native Method)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at java.lang.reflect.Method.invoke(Method.java:521)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at dalvik.system.NativeStart.main(Native Method)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04000007-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.content.res.Resources.getValue(Resources.java:888)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.content.res.Resources.openRawResource(Resources.java:813)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.content.res.Resources.openRawResource(Resources.java:795)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at com.vortex.rules.CSV_Reader.onCreate(CSV_Reader.java:18)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at com.vortex.rules.MainWindow.CreateDatabase(MainWindow.java:103)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at com.vortex.rules.MainWindow.onCreate(MainWindow.java:39)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2407)07-31 01:53:58.947: ERROR/AndroidRuntime(19573): ... 11 more
在 LogCat 之外。
这告诉我它找不到具有该 ID 的资源,但它只是从 R.java 获得了 ID,R.java 正在从编译器获取信息。
此时我完全迷失了。
任何帮助将不胜感激...
最佳答案
正如 stealthcopter 在评论中所说,您不需要文件扩展名!
关于java - Resources.getSystem().openRawResource(random.txt) 返回 Resource$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3377037/
我正在尝试通过这样做来创建输入流 InputStream is = (InputStream) getResources().openRawResource(R.drawable.image1); 但
我有一个允许用户键入文件名的 editText,但由于所有文件都在原始文件夹中。我试图从原始文件夹中获取文件,但问题出在这里, String fileName = editText.getText()
我在 res/raw 中有文件,我想这样打开: AssetFileDescriptor afd = getResources().openRawResourcesFd(); 例如,这允许通过 afd.
我想在我的 Android 应用程序中加载一个 keystore 。我已将 key (truststore.bks) 复制到文件夹 res/raw 中。来自 Android 的 SDK 生成带有 tr
我必须在 java/eclipse/android 上使用以下代码读取名为 hello.txt 的文件: import java.io.InputStream; public class Tokeni
我正在使用 plist 库加载一个 plist 文件:http://code.google.com/p/plist/我正在使用这样的代码: //InputStream ins = getResourc
当应用程序首次运行时,我试图从我的 Android 项目中的 res/raw 文件夹加载一个 XML 文件。我用这一行来做到这一点: InputStream xmlStream = getResour
我在 res/raw/ 文件夹中有一个数据库文件。我正在调用 Resources.openRawResource(),文件名为 R.raw.FileName,我得到一个输入流,但我在设备中有另一个数据
在我的 android 应用程序中,我想以静态方法访问我的文本文件,但使用以下代码: InputStream = Resources.getSystem().openRawResource(R.raw
我可以使用 ClassLoader 加载放在 res/raw/ 文件夹中的 apk 吗?为了加载 apk,我使用 openRawResources()。 最佳答案 我不知道您是否可以从 Assets
我通过对谷歌的研究发现,我可以通过将文本文件存储在我的 res/raw 文件夹中然后通过 getResources().openRawResource(R.raw.words); 访问它来读取文本文件
在 MainActivity 类中,为什么我的注释行出现空指针异常 private Context context; public MainActivity(Context con) { su
android studio 2.1. preview 4 我正在创建一个 junit4 单元测试 来测试打开原始目录中包含的文件。 但是,每次代码运行时,我都可以从 openRawResource
基于 1.6 SDK4 InputStream is = Resources.getSystem().openRawResource(R.raw.vortexrules); 这条线给我带来了无尽的麻烦
//Reading a image file from @drawable res folder and writing to a file on external sd card //below o
我是一名优秀的程序员,十分优秀!