GeeCON Prague 2014*
The moose likes Android and the fly likes cannot connect to my MySQL db using HttpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "cannot connect to my MySQL db using HttpClient" Watch "cannot connect to my MySQL db using HttpClient" New topic
Author

cannot connect to my MySQL db using HttpClient

Dov Ezra
Greenhorn

Joined: Nov 23, 2010
Posts: 21
Hello all,

I'm new to android and I'm trying to write a code that access a MySQL database.

I tried to follow the tutorial from HelloAndroid.com

I have a wamp server on my windows machine, and a MySQL database on it. and here is my code:


but all I get is the error "java.net.SocketException.permission denide".
I tried to change he post's url to "http://www.google.com" I get a java.net.UnknowenHostException
http://www.google.com.

I tried to access my php script using the android web browser, using the address http://10.0.2.2/myscript.php.
I get to the page and it run perfectly. so there is no firewall or server problems. I think.
It is something with my application. any hits, please?

Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Did you give the app internet permission?
Dov Ezra
Greenhorn

Joined: Nov 23, 2010
Posts: 21
Yes, I put that line in the manifest.xml file.

but maybe not in the right position?


I get the same permission denide error, no matter if I use HttpPost or HttpGet. is that mean anything to you?
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

It should go in the <manifest> tag.

HttpPost or HttpGet should make no difference. (for the error)
Dov Ezra
Greenhorn

Joined: Nov 23, 2010
Posts: 21
Nope, didn't help.

the manifest file looks like this:



I tried to run this code on eclipse and netbeans. the same error happends.
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Can you post the entire code (if it's not to much) and the complete error message?
Dov Ezra
Greenhorn

Joined: Nov 23, 2010
Posts: 21
Ok, here goes.
Thank you so much for your time.

//Class ConnectActivity. the main class



and that's all.

maybe its somthing with the emulator's network settings?
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Code looks good, it's working fine over here. When I run it I get the toast message, but that's not strange since it can't connect to that IP on my system. But when I change it to www.google.com it works fine. Can you post the error message including the stacktrace so I can see the line where the error occurs?
Dov Ezra
Greenhorn

Joined: Nov 23, 2010
Posts: 21
I found a solution!

I defined new AVD and used it to run the program. and it works!

This AVD used android 8 with no google APi, while the old one was android 8 with the api.
Is it possible that the API was the problem?
I hope it was someting wromg with the project or AVD configuration. why should the API be a problem?

Thanks, again!
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Weird, maybe just restarting the AVD was enough. Google or Android API should make no difference for this piece of code. I've tried it here also on a AVD with google api 8 and it worked just the same.
 
GeeCON Prague 2014
 
subject: cannot connect to my MySQL db using HttpClient