Unfortunately The Application Stopped Working
Solution 1:
As Apoorv says, you need to have permission to access any network.
<uses-permissionandroid:name="android.permission.INTERNET" />
If adding the above to your manifest doesn't fix it (or you already have that permission), the likely problem is your addresses...
privatestaticfinalStringLOGIN_URL="http://localhost/webservice/login.php";
privatestaticfinalStringLOGIN_URL="http://localhost/webservice/register.php";
I'm assuming your php server is running on the same computer as the emulator (but not on the emulator itself). If that's the case using localhost
wont work. On an emulator localhost
is the actual emulated device's loopback address and NOT the loopback address of the computer.
When using networking on an emulator you need to use 10.0.2.2 to connect to the computer's localhost / loopback address. Example...
privatestaticfinalStringLOGIN_URL="http://10.0.2.2/webservice/login.php";
privatestaticfinalStringLOGIN_URL="http://10.0.2.2/webservice/register.php";
See Using The Emulator documentation in the Emulator Networking section.
EDIT: One very likely reason for the Window Leaked error is you are trying to access objects that are in the main body of the Activities from the doInBackground
methods of your AsyncTasks. You cannot do this as doInBackground
runs on a separate thread.
In your AsyncTasks declare your username and password strings in the main body where you declare your failure boolean. Also your static final strings. Example...
classCreateUserextendsAsyncTask<String, String, String> {
privatestaticfinalString LOGIN_URL = "http://localhost/webservice/register.php";
privatestaticfinalString TAG_SUCCESS = "success";
privatestaticfinalString TAG_MESSAGE = "message";
boolean failure = false;
String username, password;
...
}
Get the text strings from the EditTexts in the onPreExecute()
method of the AsyncTasks (this method runs on the main/UI thread). Example...
@OverrideprotectedvoidonPreExecute() {
super.onPreExecute();
username = user.getText().toString();
password = pass.getText().toString();
pDialog = newProgressDialog(Login.this);
...
}
Move your JSONParser declaration and initialisation into the doInBackgoround
method of the AsyncTasks. Example...
@OverrideprotectedStringdoInBackground(String... args) {
// Check for success tag
int success;
JSONParser jsonParser = newJSONParser();
...
}
Solution 2:
There are few things which you may have missed 1. Add internet permission in your application 2. When you are calling asynctask class add where the request is of POST or GET type 3. As can be seen clearly from your logcat the url you are accessing is not valid even i tried it in my browser, it is not valid
Post a Comment for "Unfortunately The Application Stopped Working"