Resources.getSystem().openRawResource(random.txt) 返回 Resource$NotFoundException
构建于 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 exception 07-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 #0x7f040000 07-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 #0x7f040000 07-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 正在从编译器获取其信息。
此时我完全迷失了。
任何帮助将不胜感激...
Building on 1.6 SDK4
InputStream is = Resources.getSystem().openRawResource(R.raw.vortexrules);
This line is causing me no end of trouble...
My R.java shows:
public static final class raw {
public static final int vortexrules=0x7f040000;
which tells me that the compiler is recognizing the text file and the folder and setting them as a resource.
When I run the code above, trying to set the InputStream to the text file i get:
07-31 01:53:58.839: ERROR/AndroidRuntime(19573): Uncaught handler: thread main exiting due to uncaught exception 07-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 #0x7f040000 07-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 #0x7f040000 07-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
out of the LogCat.
This tells me that it can't find the resource with that ID, but it just got the ID from R.java, which is getting its information from the compiler.
I am completely lost at this point.
ANY help would be appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Stealthcopter 在评论中所说,您不需要文件扩展名!
as stealthcopter says in the comments, you dont need the file extension!