jdom not fetching anything from url [duplicate] - java

I want to parse an rss feed from an android application. Everything related to parsing the RSS feed itself is done (using SAX), however I get an exception regarding the name resolution of the feed's url.
This is the line causing the exception:
feedUrl = "http://blog.jonathanbenoudiz.com/feed/"
feedUrl.openConnection().getInputStream();
java.lang.RuntimeException:
java.net.UnknownHostException:
So I started investigating my /etc/resolv.conf file and set the nameserver to the dns server of my ISP. Pinging blog.jonathanbenoudiz.com works, but http://blog.jonathanbenoudiz.com and blog.jonathanbenoudiz.com/feed don't work (unknown host).
How am I actually supposed to do this?
Thanks!

Add the INTERNET permission to your manifest file.
You have to add this line:
<uses-permission android:name="android.permission.INTERNET" />
outside the application tag in your AndroidManifest.xml

Related

Detection error with Azure Cognitive Services: Unable to resolve host "centralus.api.cognitive.microsoft.com"

I'm using Azure Cognitive Services for an Android mobile application and got stuck on an error. Help!
Currently using the FACE API and trying to retrieve a response about the Facial Attributes but keep getting this error when I didn't have it earlier:
ERROR: Detection failed: Unable to resolve host "centralus.api.cognitive.microsoft.com": No address associated with hostname
Previously, I was only testing the facial detection with the drawFaceRectangle method, and had no errors with the endpoint but now that I'm trying to request the facial attributes I get this error. Any suggestions?
Add this line to the AndroidManifest.xml which will enable your app the permission to use the internet
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

android get restful api always timeout

I use httpclient(apache) to get a restful API when developing an Android app,just like
HttpGet httpget = new HttpGet("http://9.123.151.73:4414/apiv1/data");
HttpResponse response = httpclient.execute(httpget);
and the xml,I have set the permission:
`<uses-permission android:name="android.permission.INTERNET" />`
but it always timeout.
Then I try these cases:
Open the url in browser,it works
New a simple java project with the same code, it works
Replace the url with other rest API ,such as:
http://api.search.yahoo.co/NewsSearchService/V1/, works
So, could you give me any advices for this problem,I wonder why the rest API can not be used in Android app,what is the mistake?
I beleive it is due to the permission not set to make network connections. Here is what you need to add to your AndroidMainfest.xml file to allow access to the internet:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Here is the permission description:
INTERNET Allows applications to open network sockets.
You can check more about the permission from the link:
Here is how you can set the permission if you are using eclipse:
If you are using the Eclipse ADT plugin for your development, open
"AndroidManifest.xml" in the Android Manifest Editor (should be the
default action for opening androidmanifest.xml from the project files
list), select the "Permissions" tab along the bottom of the editor
(Manifest - Application - Permissions - Instrumentation -
AndroidManifest.xml), then "Add..." a "Uses Permission" and select the
desired permission from the dropdown on the right, or just copy paste
in the necessary one (such as the "android.permission.INTERNET"
permission you required
http://developer.android.com/reference/android/Manifest.permission.html

android ksoap2 unknown host exception for ip address

my android application communicates with .Net webservice.
i communicate with the web service using the ksoap2 library.
i see that in every time i activating method in the webservice its taking too long.
i debugged to the HttpTransportSE.call() method and i see that in the InetAddress.getHostByAddrImpl(byte[]) method there is an unknown host exception trowed after something like 20 seconds...
its strange because my url is an ip address and there is no dns lookups needed...
this exception trown even when im running this code:
InetAddress.getByName("192.168.191.110").getCanonicalHostName();
can some one explain me how to fix this?
thanks!!
Maybe you forget to add permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
EDIT
Try also this:
java.net.InetAddress[] x= java.net.InetAddress.getAllByName("192.168.191.110") ;
textView.setText("Address: "+x[0].getHostAddress());
I find that my sim card cannot access none of the available dns servers.
so i worked with the system/etc/hosts file and added the mapping there.
before the application is asking the dns server for the address there is a check of the system/etc/hosts file.
after i added the mapping there all worked well.
thanks for the help.
To use IP address you have to use getAllByName() instead of getByName(). See docs here.
So replace
InetAddress.getByName("192.168.191.110").getCanonicalHostName();
with
InetAddress.getAllByName("192.168.191.110").getCanonicalHostName();

: java.net.UnknownHostException: Unable to resolve host "hosturl": No address associated with hostname

I have android application which connect to "hosturl" over the web. This application can connect to hosturl in the initial steps, but after i try to test it for some time(say 20 or more requests), I get above exception and I can not no longer connect to above url.
If i restart my android handset, then application can again connect to the "hosturl" but again I get the exception after I have tried to connect to hosturl few number of times
Could anybody help me here If you have encounter such a behavior with an android application before.
You probably don't have the INTERNET permission. Try adding this to your AndroidManifest.xml file, right before </manifest>:
<uses-permission android:name="android.permission.INTERNET" />
I met this and I just closed my AVD and start it again and it worked...
Check your Internet connection.
Check Wifi.
Check Server.

Android - UnknownHost exception when parsing an RSS feed

I want to parse an rss feed from an android application. Everything related to parsing the RSS feed itself is done (using SAX), however I get an exception regarding the name resolution of the feed's url.
This is the line causing the exception:
feedUrl = "http://blog.jonathanbenoudiz.com/feed/"
feedUrl.openConnection().getInputStream();
java.lang.RuntimeException:
java.net.UnknownHostException:
So I started investigating my /etc/resolv.conf file and set the nameserver to the dns server of my ISP. Pinging blog.jonathanbenoudiz.com works, but http://blog.jonathanbenoudiz.com and blog.jonathanbenoudiz.com/feed don't work (unknown host).
How am I actually supposed to do this?
Thanks!
Add the INTERNET permission to your manifest file.
You have to add this line:
<uses-permission android:name="android.permission.INTERNET" />
outside the application tag in your AndroidManifest.xml

Categories

Resources