Issue
I need to read an xml file from my xml folder, and but I'm getting no such file
error. Can anyone tell me how can i read XML file from the xml folder in android?
Here is my code:
InputSource inputSource = new InputSource(getResources().openRawResource(
getResId("R.xml." + fileName.substring(0,fileName.length() - 4),
AlbumDetails.class)));
And logCat output:
12-17 14:32:59.513: W/System.err(3563): java.lang.NoSuchFieldException: R.xml.quran_simple
12-17 14:32:59.513: W/System.err(3563): at java.lang.Class.getDeclaredField(Class.java:631)
12-17 14:32:59.513: W/System.err(3563): at com.darkovski.quran.AlbumDetails.getResId(AlbumDetails.java:250)
12-17 14:32:59.513: W/System.err(3563): at com.darkovski.quran.AlbumDetails$3.doInBackground(AlbumDetails.java:282)
12-17 14:32:59.513: W/System.err(3563): at com.darkovski.quran.AlbumDetails$3.doInBackground(AlbumDetails.java:1)
12-17 14:32:59.513: W/System.err(3563): at android.os.AsyncTask$2.call(AsyncTask.java:264)
12-17 14:32:59.513: W/System.err(3563): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-17 14:32:59.513: W/System.err(3563): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-17 14:32:59.513: W/System.err(3563): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
12-17 14:32:59.513: W/System.err(3563): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-17 14:32:59.513: W/System.err(3563): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-17 14:32:59.513: W/System.err(3563): at java.lang.Thread.run(Thread.java:856)
12-17 14:32:59.513: W/ResourceType(3563): No known package when getting value for resource number 0xffffffff
12-17 14:32:59.513: W/dalvikvm(3563): threadid=16: thread exiting with uncaught exception (group=0x2b542210)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): 17-12-13 14:32:59:524 Unexpected problem on thread AsyncTask #3: An error occured while executing doInBackground()
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): 17-12-13 14:32:59:530 java.lang.RuntimeException: An error occured while executing doInBackground()
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.os.AsyncTask$3.done(AsyncTask.java:278)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.lang.Thread.run(Thread.java:856)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.content.res.Resources.getValue(Resources.java:1018)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.content.res.Resources.openRawResource(Resources.java:943)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.content.res.Resources.openRawResource(Resources.java:925)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at com.darkovski.quran.AlbumDetails$3.doInBackground(AlbumDetails.java:281)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at com.darkovski.quran.AlbumDetails$3.doInBackground(AlbumDetails.java:1)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at android.os.AsyncTask$2.call(AsyncTask.java:264)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-17 14:32:59.523: E/Burstly SDK v.1.34.0.46238 BackgroundUncaughtExceptionHandler(3563): ... 5 more
Solution
if you need an inputstream out of it simply put the xml into raw resources and open it with
InputStream inputStream = getResources().openRawResource(R.raw.fileName);
Answered By - Pasquale Anatriello
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.