android ksoap2 unknown host exception for ip address - java

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();

Related

java.io.FileNotFoundException when trying accessing localhost file in android physical device

I am new to android and java. I am trying to develop a test app which gets data stored in local database. I am using WAMPP. In emulator I can access it perfectly, but when I try to access it in my physical device (Micromax A311) I get java.io.FileNotFoundException. I have seen many questions asked for this question, but none worked for me.
In my AndroidManifesti have added following code
<uses-permission android:name="android.permission.INTERNET"/>
Url
String url="http://192.168.0.104/selectQuery.php";
which is my IP4 (Wireless LAN adapter Wi-Fi) address.
I have tried it with
http://10.0.2.2/....
/10.0.2.2:80/....
/192.168.0.104:80/
I can access data in browser saved in my database using
/192.168.0.104/ and /192.168.0.104:80/
I am connected physical device via USB to laptop. In my tethering setting I turned USB tethering on.
I am connected with same WiFi which is connected to my laptop.
My proxy setting of laptop is also off.
Can anyone help me to get out of this problem.. I am struck in this from past few days..
Thank you
If selectQuery.php file is in a folder your url is like:
String url ="http://192.168.0.104/name_folder/selectQuery.php";
So if have ./myFolder/selectQuery.php the url is:
String url = "http://192.168.0.104/myFolder/selectQuery.php";
Thanks for your reply... I found a solution myself. I downloaded https://ngrok.com/download, then used its CMD and copy pasted
ngrok http -bind-tls=false site.dev:80
which i found in https://ngrok.com/docs#bind-tls under Tunneling only HTTP or HTTPS. Then I used forwarding address in my url string.
It worked Fine.. I am happy now..

Error connecting to Oracle database using JDBC [duplicate]

I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.

GWT-SyncProxy for android : No remoteService in the classpath

In android client consuming my LoginService remote service, in order to connect user to the application.
I use gwt-syncproxy librairie to acces to my remote interface. And the following warning occured:
RpcPolicyFinder:No RemoteService in the classpath
followed by :
java.io.FileNotFoundException:
http:// localhost: . . . /. . ./application/application.nocache.js
Is there someone who had experienced this type of trouble ?
Please review the Android and CommonIssues wiki pages for the project as these clarify some common issues with the library.
In the meantime, more specifically, I often see this type of issue (though not this exactly) when the library has not been GWT-compiled or if the local server is not running where the Android app is expecting to find it. If you're not using App-Engine and are testing locally, make sure you are using Android's host Loopback interface with the #setLoginUrl method (GAELogin, Android Emulator networking).
Try posting the full error with details so we can see where it might be pointing wrong.
I think this issue is caused by a few reason:
1. You site is required login. And I checked the code of SyncProxy(0.5), it doesn't support if a site is secure.
2. SyncProxy will download some files from server side, for example:
compilation-mappings.txt
*.nocache.js
*.cache.html
*.gwt.rpc
If SyncProxy cannot download them, this error may occur, please check it these files can be download and the uri and name format of them is as default.
I was contacting with the owner of SyncProxy to improve this feature to support basic cookie/sessionid checking of auth.
https://github.com/jcricket/gwt-syncproxy/issues/46#issuecomment-89271311

: 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, UnknownHostException: www.google.com, on device,not emulator

I'm using google api java client for connecting to Google Docs in Android app.
Once in a while i get following exception:
UnknownHostException: www.google.com
Code:
transport = AndroidHttp.newCompatibleTransport();
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "writely";
authenticator.username = username.getText().toString();
authenticator.password = password.getText().toString();
authenticator.transport = transport;
authenticator.authenticate().getAuthorizationHeaderValue();
Device reset clears exception but is it necessary.
I suspected for DNS caching and tried following but didnt work. Im not behind a proxy as far I know.
Security.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.negative.ttl","0");
System.setProperty("net.eth0.dns1","8.8.8.8");
System.setProperty("net.dns1","8.8.8.8");
Last time it occurred was this morning when one network connection "died", cell auto got second one, tried to do ClientLogin but failed with exception.
Just to make it clear, Im talking about DEVICE (htc desire hd), not emulator.
Thanks in advance.
add this line to your AndroidManifest.xml file, just after the <manifest> tag and before the <application> tag:
<uses-permission android:name="android.permission.INTERNET" />
I run into this daily. I think it is a bug in the emulator. After reset of emulator it works again and it never happened on a real device.
Edit: most definitely a bug in the emulator. See this thread. There are also several posts on StackOverflow regarding those emulator connection issues.

Categories

Resources