Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot connect to my MySQL db using HttpClient

 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you give the app internet permission?
 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should go in the <manifest> tag.

HttpPost or HttpGet should make no difference. (for the error)
 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the entire code (if it's not to much) and the complete error message?
 
Dov Ezra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic