Monday, 15 July 2013

How to get XML data from assets in android? -


I have stored an XML file in the property folder, and I want to recover the data XML file, I store in the property, give me a solution.

  & lt; Feedback & gt; & Lt; RequestID & gt; 1001 & lt; / RequestID & gt; & Lt; FunctionStatus & gt; & Lt; / FunctionStatus & gt; & Lt; Message & gt; & Lt; / Messages & gt; & Lt; Results & gt; & Lt; Banner & gt; & Lt; Banner_List & gt; & Lt; Banner_id & gt; 3794 & lt; / Banner_id & gt; & Lt; Banner_url & gt; Http: //www.metromatinee.com/agile_dogs/05.jpg< / Banner_url & gt; & Lt; MovieName & gt; Rose Guitaral & lt; / Movie_name & gt; & Lt; Gender & gt; Movie & lt; / Gender & gt; & Lt; / Banner_List & gt; & Lt; / Reaction & gt;   

I have tried InputStream = getAssets (). Open ("demo.xml");

Due to the exception
Any help .. ???

  03-27 11: 03: 04.939: E / Android sequence (432): fatal exception: main 03-27 11: 03: 04.939: E / Android randomime (432): java. lang.NullPointerException 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): android.content.ContextWrapper.getAssets (ContextWrapper.java:74) in 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432) on com.service.example.DemoBussinessExecutePage.executeBussinessFunction (DemoBussinessExecutePage.java:230) 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): com.service.example.Service_Manager.executeBussinessFunction on ( Service_Manager.java38) 03-27 November: 03: 04.9 3 9: E / AndroidRuntime (432): $ 1.onClick (Service_class.java:57) at com.service.example.Service_class 03-27 Nov: 03: 04.9 3 9: E / AndroidRuntime (432): 03 :: 0 4.9 3 9: E / AndroidRuntime (432): android.view.View.performClick (View.java:2408) on November 3-27, at android.view.View $ PerformClick.run (see Java: 8816) 03-27 11:03: 04.9 3 9: E / AndroidRuntime (432): at android.os.Handler.handleCallback (Handler.java lesson87) 03-27 Nov: 03: 04.9 3 9: E / AndroidRuntime (432): android on os.Handler.dispatchMessage (handler java: 92) 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): android.os.Looper.loop (Looper.java:123) for 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): android.app.ActivityThread.main 03-27 on (ActivityThread.java:4627) 11: 03: 04.9 3 9: e / AndroidRuntime (432): the java.lang .reflect.Method.invokeNative (Native Method) 03-27 11: 03: 04.9 3 9: E / AndroidRuntime (432): at java.lang.reflect.Method.invoke (Meth od.java:521) 03-27 November 03: 04k9 3 9 E / AndroidRuntime (432): .internal.os.ZygoteInit $ MethodAndArgsCaller.run on com.android (ZygoteInit.java:868) 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): com.android.internal.os.ZygoteInit.main (on ZygoteInit.java: 626) 03-27 November 03: 04k9 3 9 e / AndroidRuntime (432): On dalvik.system.NativeStart.main (Native Method)    

Found the solution

  AssetManager am = Class.getAssets (); Try {InputStream = am.open ("1001.xml"); Int length = is.available (); Byte [] data = new byte [length]; Is.read (data); DemoInput = new string (data) .toString (); } Hold (IOException e1) {e1.printStackTrace (); }    

No comments:

Post a Comment