English 中文(简体)
DEBUG/SntpClient(60):请求时间失败:java.net。 SocketException: 解决家庭问题; 解决家庭问题; 解决家庭问题; 解决家庭问题。
原标题:DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol getting this exception
  • 时间:2011-09-17 05:21:04
  •  标签:
  • android
 And some times i m getting java.net.MalFormedURLException what s the reason behind this and how can i resolve this..

My code is as follows..


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

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL(
                "http://w3devadv.liveproj.com  /api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5");

        /**
         * Create handler to handle XML Tags ( extends DefaultHandler )
         */
        DealsHandler myXMLHandler = new DealsHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));


In handler i m writing the following code in startelement  

public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {
    currentElement = true;
    if (localName.equalsIgnoreCase("data")) {
        dealsdata = new DealsData();
    } else if (localName.equalsIgnoreCase("dealdetails")) {
        deals = new Deals();
    } else if (localName.equalsIgnoreCase("title")) {
        deals.title = attributes.getLocalName(0);
    }

i m getting the above said exception how can i resolve this.
最佳回答

You are getting this error because.....

"This exception is thrown when a program attempts to create an URL from an
incorrect specification."
问题回答

before passing the string to url you can Convert the string to Standard URL format

这种做法。

String url = new String(str.trim().replace(" ", "%20").replace("&", "%26")
.replace(",", "%2c").replace("(", "%28").replace(")", "%29")
.replace("!", "%21").replace("=", "%3D").replace("<", "%3C")
.replace(">", "%3E").replace("#", "%23").replace("$", "%24")
.replace(" ", "%27").replace("*", "%2A").replace("-", "%2D")
.replace(".", "%2E").replace("/", "%2F").replace(":", "%3A")
.replace(";", "%3B").replace("?", "%3F").replace("@", "%40")
.replace("[", "%5B").replace("\", "%5C").replace("]", "%5D")
.replace("_", "%5F").replace("`", "%60").replace("{", "%7B")
.replace("|", "%7C").replace("}", "%7D"));

你们可以在你任满时使用“URL”这一功能,这样你就可以克服错误,做你的工作。

i know you accepted the answer but this could also help other also i think Thank You.

"http://w3devadv.liveproj.com  /api/apiRequest.php?Method=getdealdetails&DealId=2&SessionId=EA3JQ0RZJT4e66223143fc5"

It is probably due to the space in the URL.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签