thabikkmcq
New Member
I am trying to download a xml file from a URL, save it to the internal sd card and parse the xml. This is my download function:\[code\]private static String Name = project_name.getText().toString();private static String URL = url.getText().toString();//Download XML file from URL DownloadManager.Request request = new DownloadManager.Request(Uri.parse(URL));request.setTitle("Download von "+Name+".xml");request.setDestinationInExternalPublicDir("/", Name+".xml");// get download service and enqueue fileDownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);manager.enqueue(request); private static ArrayList<Datapoint> itemsList = parseXML();\[/code\]This is the parser function:\[code\]private ArrayList<Datapoint> parseXML() { try { Log.w("AndroidParseXMLActivity", "Start"); /** Handling XML */ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); File file = new File(Environment.getExternalStorageDirectory()+"/"+ Name+ ".xml"); XMLContentHandler myXMLHandler = new XMLContentHandler(); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(new InputStreamReader(new FileInputStream(file)))); itemsList = myXMLHandler.getItemsList(); Log.w("AndroidParseXMLActivity", "Done"); } catch (Exception e) { Log.w("AndroidParseXMLActivity",e ); } return itemsList ; }\[/code\]But I get the following Logcat error:\[code\]09-28 09:30:36.500: W/AndroidParseXMLActivity(7881): Start09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): java.io.FileNotFoundException: /mnt/sdcard/mich.xml: open failed: ENOENT (No such file or directory)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at libcore.io.IoBridge.open(IoBridge.java:406)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at java.io.FileInputStream.<init>(FileInputStream.java:78)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at de.bertrandt.bertrandtknx.CreateProject.parseXML(CreateProject.java:348)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at de.bertrandt.bertrandtknx.CreateProject.save_project(CreateProject.java:298)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at de.bertrandt.bertrandtknx.CreateProject.onOptionsItemSelected(CreateProject.java:115)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.app.Activity.onMenuItemSelected(Activity.java:2564)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:984)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:613)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:121)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.view.View.performClick(View.java:3644)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.view.View$PerformClick.run(View.java:14313)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.os.Handler.handleCallback(Handler.java:605)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.os.Handler.dispatchMessage(Handler.java:92)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.os.Looper.loop(Looper.java:137)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at android.app.ActivityThread.main(ActivityThread.java:4517)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at java.lang.reflect.Method.invokeNative(Native Method)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at java.lang.reflect.Method.invoke(Method.java:511)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at dalvik.system.NativeStart.main(Native Method)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at libcore.io.Posix.open(Native Method)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): at libcore.io.IoBridge.open(IoBridge.java:390)09-28 09:30:36.540: W/AndroidParseXMLActivity(7881): ... 22 more09-28 09:30:36.590: E/SKIA(7881): FimgApiStretch:stretch failed09-28 09:30:39.350: D/AbsListView(7881): Get MotionRecognitionManager09-28 09:30:39.435: D/dalvikvm(7881): GC_CONCURRENT freed 238K, 5% free 15465K/16135K, paused 1ms+4ms09-28 09:30:39.440: D/AbsListView(7881): [unregisterDoubleTapMotionListener]09-28 09:30:39.440: I/MotionRecognitionManager(7881): .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@41a3a5e009-28 09:30:40.675: D/FILESTREAM(7881): Filepath:/data/data/de.bertrandt.bertrandtknx/files/mich09-28 09:30:40.675: D/AndroidRuntime(7881): Shutting down VM09-28 09:30:40.675: W/dalvikvm(7881): threadid=1: thread exiting with uncaught exception (group=0x40c621f8)09-28 09:30:40.680: E/AndroidRuntime(7881): FATAL EXCEPTION: main09-28 09:30:40.680: E/AndroidRuntime(7881): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bertrandt.bertrandtknx/de.bertrandt.bertrandtknx.ProjectView}: java.lang.NullPointerException09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread.access$600(ActivityThread.java:128)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.os.Handler.dispatchMessage(Handler.java:99)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.os.Looper.loop(Looper.java:137)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread.main(ActivityThread.java:4517)09-28 09:30:40.680: E/AndroidRuntime(7881): at java.lang.reflect.Method.invokeNative(Native Method)09-28 09:30:40.680: E/AndroidRuntime(7881): at java.lang.reflect.Method.invoke(Method.java:511)09-28 09:30:40.680: E/AndroidRuntime(7881): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)09-28 09:30:40.680: E/AndroidRuntime(7881): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)09-28 09:30:40.680: E/AndroidRuntime(7881): at dalvik.system.NativeStart.main(Native Method)09-28 09:30:40.680: E/AndroidRuntime(7881): Caused by: java.lang.NullPointerException09-28 09:30:40.680: E/AndroidRuntime(7881): at de.bertrandt.bertrandtknx.ProjectView.setup(ProjectView.java:148)09-28 09:30:40.680: E/AndroidRuntime(7881): at de.bertrandt.bertrandtknx.ProjectView.onCreate(ProjectView.java:62)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.Activity.performCreate(Activity.java:4533)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)09-28 09:30:40.680: E/AndroidRuntime(7881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)09-28 09:30:40.680: E/AndroidRuntime(7881): ... 11 more\[/code\]I have also set this permission in my AndroidManifest.xml\[code\]<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>\[/code\]The xml is downloaded and saved to the sd card because I can see and open it with the windows explorer.Anyone a idea?