1

hi all I am new in xml parsing when I am fetching xml from url and call url.openStream() method IO exception produce anyone help me..

SAXParserFactory spf =SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL("http://api.androidhive.info/music/music.xml");
        DataHandler mdaDataHandler = new DataHandler();
        xr.setContentHandler(mdaDataHandler);
         InputStream io = sourceUrl.openStream();//exception is here
        xr.parse(new InputSource(io));
        mmusic = mdaDataHandler.getParseData();

exception is this

04-15 15:07:06.310: W/System.err(590): java.net.SocketException: Permission denied
04-15 15:07:06.440: W/System.err(590):  at      
org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
04-15 15:07:06.440: W/System.err(590):  at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
04-15 15:07:06.450: W/System.err(590):  at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
04-15 15:07:06.460: W/System.err(590):  at java.net.Socket.checkClosedAndCreate(Socket.java:873)
04-15 15:07:06.460: W/System.err(590):  at java.net.Socket.connect(Socket.java:1020)
04-15 15:07:06.470: W/System.err(590):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
04-15 15:07:06.470: W/System.err(590):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
04-15 15:07:06.480: W/System.err(590):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
04-15 15:07:06.490: W/System.err(590):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
04-15 15:07:06.490: W/System.err(590):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1152)
04-15 15:07:06.500: W/System.err(590):  at java.net.URL.openStream(URL.java:653)
04-15 15:07:06.500: W/System.err(590):  at com.listview.experiment.CustomListViewActivity.parseXML(CustomListViewActivity.java:56)
04-15 15:07:06.510: W/System.err(590):  at com.listview.experiment.CustomListViewActivity.access$0(CustomListViewActivity.java:43)
04-15 15:07:06.520: W/System.err(590):  at com.listview.experiment.CustomListViewActivity$1.onClick(CustomListViewActivity.java:34)
04-15 15:07:06.520: W/System.err(590):  at android.view.View.performClick(View.java:2408)
04-15 15:07:06.520: W/System.err(590):  at android.view.View$PerformClick.run(View.java:8816)
04-15 15:07:06.530: W/System.err(590):  at android.os.Handler.handleCallback(Handler.java:587)
04-15 15:07:06.540: W/System.err(590):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-15 15:07:06.550: W/System.err(590):  at android.os.Looper.loop(Looper.java:123)
04-15 15:07:06.550: W/System.err(590):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-15 15:07:06.550: W/System.err(590):  at java.lang.reflect.Method.invokeNative(Native Method)
04-15 15:07:06.560: W/System.err(590):  at java.lang.reflect.Method.invoke(Method.java:521)
04-15 15:07:06.570: W/System.err(590):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 15:07:06.570: W/System.err(590):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 15:07:06.570: W/System.err(590):  at dalvik.system.NativeStart.main(Native Method)

manifest is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.sam.testParsing"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-sdk android:minSdkVersion="8" />
   <application
     android:icon="@drawable/ic_launcher"
       android:label="@string/app_name" >
       <activity
          android:label="@string/app_name"
           android:name=".XMLParsingActivity" >
              <intent-filter >
                   <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                  </intent-filter>
                   </activity>
               </application>
           </manifest>
7
  • Please post a stack trace of the exception from logcat. Commented Apr 15, 2012 at 15:06
  • do you have android.permission.INTERNET in your permissions in android manifest Commented Apr 15, 2012 at 15:10
  • yes I have been put this permission.. Commented Apr 15, 2012 at 15:11
  • 04-15 15:07:06.310: W/System.err(590): java.net.SocketException: Permission denied Commented Apr 15, 2012 at 15:13
  • 1
    if you are behind a proxy, then see if you can browse in the emulator, using the default browser, try to open you url from there Commented Apr 15, 2012 at 15:21

2 Answers 2

3

You can't call Url.openStream() on the UI thread. Use AsyncTask to perform this operation and correctly update the UI when finished. `

Sign up to request clarification or add additional context in comments.

Comments

1

You need to add this to your manifest file:

<uses-permission android:name="android.permission.INTERNET">

Make sure that it is just below the <manifest> tag.

5 Comments

I have allready put this permission I am using emulator for testing is any issue may be by emulator.
please help me why this exception come?
@sandee - That error almost always comes because the manifest is missing the <uses-permission> tag or the tag is in the wrong place in the manifest file. Can you post your manifest file in your original question? If the emulator configuration was the problem, I think there would be a different exception message.
@sandee - One other problem might be the firewall setting on your computer. Try accessing the url from the emulator's browser.
this url is open properly in emulator means when I am putting that url manually on emulaator browser proper data is showing..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.