林XML解析開發中機器人即時通訊應用程序解析存儲在RES /原始文件夾中的XML但是我得到一個錯誤FileNotFound 繼承人我的代碼FileNotFoundException異常在機器人
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);
InputStream is = this.getResources().openRawResource(R.raw.earth);
try{
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(is,null);
}catch(ParserConfigurationException e){
Log.d("XML parse Error:",e.getMessage());
return;
}catch(SAXException e){
Log.d("Wrong XML File Structure",e.getMessage());
return;
}catch(IOException e){
Log.d("IOException", e.getMessage());
return;
}
登錄貓
12-08 14:37:17.893: E/AndroidRuntime(502): Uncaught handler: thread main exiting due to uncaught exception
12-08 14:37:17.923: E/AndroidRuntime(502): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.xml/org.example.xml.XMLparseActivity}: android.content.res.Resources$NotFoundException: File Hello World, XMLparseActivity! from drawable resource ID #0x7f040000
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.os.Handler.dispatchMessage(Handler.java:99)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.os.Looper.loop(Looper.java:123)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-08 14:37:17.923: E/AndroidRuntime(502): at java.lang.reflect.Method.invokeNative(Native Method)
12-08 14:37:17.923: E/AndroidRuntime(502): at java.lang.reflect.Method.invoke(Method.java:521)
12-08 14:37:17.923: E/AndroidRuntime(502): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-08 14:37:17.923: E/AndroidRuntime(502): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-08 14:37:17.923: E/AndroidRuntime(502): at dalvik.system.NativeStart.main(Native Method)
12-08 14:37:17.923: E/AndroidRuntime(502): Caused by: android.content.res.Resources$NotFoundException: File Hello World, XMLparseActivity! from drawable resource ID #0x7f040000
12-08 14:37:17.923: E/AndroidRuntime(502): at android.content.res.Resources.openRawResource(Resources.java:822)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.content.res.Resources.openRawResource(Resources.java:798)
12-08 14:37:17.923: E/AndroidRuntime(502): at org.example.xml.XMLparseActivity.onCreate(XMLparseActivity.java:47)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
12-08 14:37:17.923: E/AndroidRuntime(502): ... 11 more
12-08 14:37:17.923: E/AndroidRuntime(502): Caused by: java.io.FileNotFoundException: Hello World, XMLparseActivity!
12-08 14:37:17.923: E/AndroidRuntime(502): at android.content.res.AssetManager.openNonAssetNative(Native Method)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.content.res.AssetManager.openNonAsset(AssetManager.java:390)
12-08 14:37:17.923: E/AndroidRuntime(502): at android.content.res.Resources.openRawResource(Resources.java:819)
12-08 14:37:17.923: E/AndroidRuntime(502): ... 15 more
如有任何線索,請回復
如果您確定該文件位於原始文件夾中,請執行清理然後生成 – rfsk2010
是的,我清理並構建了相同的錯誤 –
請確保您的文件在res/raw/your_file中。 –