3
大廈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,它從編譯器獲取其信息。
我完全失去了這一點。
任何幫助,將不勝感激...
如果你在標題(Resources.getSystem()。openRawResource(random.txt))中寫入它時調用它,那麼你會得到一個錯誤,因爲在加載資源時不應該包含文件擴展名,所以它'd只是'隨機' – stealthcopter 2010-07-31 16:15:02
對於遲來的回覆,是的,我發現,但thnx的迴應! – 2010-08-02 16:34:35
現在你應該接受你自己的答案。 – 2012-01-26 07:28:08