• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting Android app to Servlet

 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello I am trying to connected my Android App to my Servlet running on the same machine, to run as a client server architecture. What is happening is when I click on my app, I am getting "Unfortunately "FridgeProj" has stopped. Just fyi, I am new to this and I am trying to run the code on this website:

webpage

Here is my code:
activitiy_fridge_appliance.xml



FridgeAppliance.java




R.java


strings.xml



FridgeProjManifest.xml


Please let me know what am I doing wrong.

Thank you,
Luke.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting "Unfortunately "FridgeProj" has stopped.

Open a command line window and run "adb logcat" - that gives you all the logging output, including in this case the stack trace of the exception that killed the app.

my Android App to my Servlet running on the same machine

Does this mean the app runs in the emulator, and your machine is 10.200.170.12? If so, that's not going to work. You need to use 10.0.2.2 as the IP address to connect to the local machine from within the emulator.

LINEARLAYOUT, TEXTVIEW, EDITTEXT, BUTTON

I've never seen all uppercase spelling; I doubt that that is going to work since XML is case-sensitive. Try LinearLayout, TextView, EditText and Button instead.

I'm assuming that "activitiy_fridge_appliance.xml " is just a copy/paste typo in your post.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Ulf for letting me know about the debugger, I was actually thinking about it.

If my ipaddress is something like: 104.15.20.4, what would my emulator's address be? I mean how did you get the 10.0.2.2 address?

Thank you for assisting me about the activity_fridge_appliance.xml and strings.xml, it is working. Here is the code:




In the EditText, it was giving me a warning, to include "hint" or "text", so I just put empty as above, can I do that?

strings.xml


Thank you,
Luke.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ulf for letting me know about the debugger, I was actually thinking about it.

"adb logcat" isn't a debugger, it merely prints the debugging output to the console. You will become very familiar with it over time, and also with the android.util.Log class that you use to print stuff into the log.

I mean how did you get the 10.0.2.2 address?

That's documented: http://developer.android.com/tools/devices/emulator.html#networkaddresses

As long as the app does what you want it to do, you can ignore warnings. You may want to read the documentation about what these attributes do, though, just in case it's something you want to use as well.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Ulf, my project worked!! after changing the ip address. Thank you very much for your timely assistance.

One more thing why does my emulator take a long time to load up?

These are the parameters I am setting for my Android Virtual Device (AVD):
Device: 3.2" QVGA (ADP2) (320 * 480: mdpi)
Target: Android 4.4 - API Level 19
Memory Optioins: RAM 768 VM Heap: 16
Internal Storage: 500

Thank you,
Luke.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "a long time"? In my experience, AVDs tend to boot up faster the smaller the screen is, and the older the Android version is. Since your screen is pretty small already, try an older Android version (like 2.3.3) to see if that makes a difference. (Obviously, the faster the desktop computer you do this on, the better.)
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

By long I mean around 4 to 5 minutes. I am not able to reduce the version on the AVD when I edit the settings, the only option it is giving me is:
Android 4.4 - API Level 19, do you know where to change the settings Android 2.3.3. My computer is 4 GB ram.

Also another problem I am encountering is when I am running my application on the desktop it is running fine, but when I am running this app on my laptop it is not able to connect to my emulator. Do you have any ideas?, I disabled the firewall/Anti Virus and still could not connect to my servlet?

Thank you for help Ulf.

Luke.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to reduce the version on the AVD when I edit the settings, the only option it is giving me is:
Android 4.4 - API Level 19, do you know where to change the settings Android 2.3.3

All available options are displayed in the popup menu (assuming you're using the "android" tool that comes with the SDK). You need to install other Android versions first before you can create AVDs for them (also using that tool).

when I am running this app on my laptop it is not able to connect to my emulator. Do you have any ideas?, I disabled the firewall/Anti Virus and still could not connect to my servlet?

Have you changed the IP address the app uses to whatever IP your server is running on? Is there nothing in the logcat?
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

On the Logcat here the following output:




I have included the code to check about ipaddress in ApplianceActivity.java and I am getting 10.0.2.15









 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The IP address of the device doesn't matter, the important thing is the IP address of the server. I see you're still using 10.0.2.2 for that, which means the emulator would try to access localhost on the laptop; is that where the server runs?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably the point where you should create a static IP or domain you can access your application from the outside world. For example, you wouldn't access Google's search using the computer's local network IP address, you would use the www.google.com domain. Similarly you should create one for the Web portion of your application so you can get access to it in a consistent way without having to re-code the IP address depending on where it is run.

If you don't have a domain set up, there are free ones you can use (the one I use is http://www.no-ip.com/ for this sort of thing: you can get sub domains with myapp.sytes.net or somesuch and direct them to your computer until you get your own domain). You will also have other configurations (like firewalls and possibly working around your ISP) to deal with, but some quick google-ing will help with that if you don't know what needs to be done.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf, thanks for the reply. Yes the server and the emulator are on the same machine (laptop). It is working fine on my desktop but not on my laptop. The same thing happenend when I ran an normal client server TCP socket program. It was running on my windows xp desktop but not on my Windows 7 laptop.

Steve, thanks for your reply, I will try to research and find more about no-ip website.

Thanks,
Luke.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies, did not know that I have to remove them, otherwise I would have.

here is the output from my logcat, some of these may not be mine, but removed most of them where my project is not mentioned. My Project name is:
MyAppliances, package: com.project.myappliances



 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's too much to expect anyone to go through. Remove everything that's not coming from your app.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check, updated the log. Apologies for the big one.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see nothing written by the app in there, just that it has been installed and started. Not even the "inputString" line, which suggests to me that the code is never run. Put some logging before lines 41, 44 and 50 to make sure that code is actually executed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic