当前位置: 动力学知识库 > 问答 > 编程问答 >

login - Android app wont work after restarting pc

问题描述:

hi i am currently working in our android project.. and my code works fine last night before i went to bed.. after openning it again.. it cannot even execute my loginpage activity..

this is my loginpage.java

`

package info.androidhive.slidingmenu;

import java.util.ArrayList;

import java.util.List;

import org.apache.http.NameValuePair;

import org.apache.http.message.BasicNameValuePair;

import org.json.JSONException;

import org.json.JSONObject;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.os.AsyncTask;

import android.os.Bundle;

import android.preference.PreferenceManager;

import android.text.InputType;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import android.widget.ToggleButton;

public class LoginPage extends Activity implements OnClickListener {

private EditText username, password;

private Button mSubmit;

private ToggleButton mShowPass;

// Progress Dialog

private ProgressDialog pDialog;

// JSON parser class

JSONParser jsonParser = new JSONParser();

// php login script location:

// localhost :

// testing on your device

// put your local ip instead, on windows, run CMD > ipconfig

// or in mac's terminal type ifconfig and look for the ip under en0 or en1

// private static final String LOGIN_URL =

// "http://xxx.xxx.x.x:1234/webservice/login.php";

// testing on Emulator:

private static final String LOGIN_URL = "http://192.168.10.4/NurseStation/android/physicianlogin.php";

// testing from a real server:

// private static final String LOGIN_URL =

// "http://www.yourdomain.com/webservice/login.php";

// JSON element ids from repsonse of php script:

private static final String TAG_SUCCESS = "success";

private static final String TAG_MESSAGE = "message";

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.loginpage);

// setup input fields

username = (EditText) findViewById(R.id.etusername);

password = (EditText) findViewById(R.id.etpassword);

// setup buttons

mSubmit = (Button) findViewById(R.id.login);

mShowPass = (ToggleButton) findViewById(R.id.showPassword);

// listeners

mSubmit.setOnClickListener(this);

mShowPass.setOnClickListener(this);

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

switch (v.getId()) {

case R.id.login:

new AttemptLogin().execute();

break;

case R.id.showPassword:

if (mShowPass.isChecked()) {

password.setInputType(InputType.TYPE_CLASS_TEXT

| InputType.TYPE_TEXT_VARIATION_PASSWORD);

} else {

password.setInputType(InputType.TYPE_CLASS_TEXT);

}

break;

default:

break;

}

}

class AttemptLogin extends AsyncTask<String, String, String> {

/**

* Before starting background thread Show Progress Dialog

* */

boolean failure = false;

@Override

protected void onPreExecute() {

super.onPreExecute();

pDialog = new ProgressDialog(LoginPage.this);

pDialog.setMessage("Attempting login...");

pDialog.setIndeterminate(false);

pDialog.setCancelable(false);

pDialog.show();

}

@Override

protected String doInBackground(String... args) {

// TODO Auto-generated method stub

// Check for success tag

int success;

try {

// Building Parameters

List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("username", username

.getText().toString().trim()));

params.add(new BasicNameValuePair("password", password

.getText().toString().trim()));

Log.d("request!", "starting");

// getting product details by making HTTP request

JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",

params);

// check your log for json response

Log.d("Login attempt", json.toString());

// json success tag

success = json.getInt(TAG_SUCCESS);

if (success == 1) {

Log.d("Login Successful!", json.toString());

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginPage.this);

Editor edit = sp.edit();

edit.putString("username", username.getText().toString().trim());

edit.commit();

Intent OpenMainActivity = new Intent(

"info.androidhive.slidingmenu.OPENMAINACTIVITY");

OpenMainActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

OpenMainActivity.putExtra("EXIT", false);

finish();

startActivity(OpenMainActivity);

return json.getString(TAG_MESSAGE);

} else if (success != 1) {

Log.d("Login Failure!", json.getString(TAG_MESSAGE));

return json.getString(TAG_MESSAGE);

}

} catch (JSONException e) {

e.printStackTrace();

}

return null;

}

/**

* After completing background task Dismiss the progress dialog

* **/

protected void onPostExecute(String file_url) {

// dismiss the dialog once product deleted

pDialog.dismiss();

if (file_url != null) {

Toast.makeText(LoginPage.this, file_url, Toast.LENGTH_LONG)

.show();

}

}

}

}

`

and this is my php code since my code is connected to my remote server..

<?php

//load and connect to MySQL database stuff

//require("config.inc.php");

//mysql_connect("localhost","androidapp","RZDJ45xzvfzuTf6C");

mysql_connect("localhost","root","");

mysql_select_db("myhs");

$username = $_POST['username'];

$password = $_POST['password'];

$query_search = "SELECT * FROM physicians WHERE physicianUsername = '".$username."' AND physicianPassword = '".$password. "'";

//$query_search = "SELECT * FROM physicians ";

$query_exec = mysql_query($query_search) or die(mysql_error());

$rows = mysql_num_rows($query_exec);

//echo $rows;

if($rows == 0) {

//echo "No Such User Found";

$response["success"] = 0;

$response["message"] = "Invalid Credentials!";

die(json_encode($response));

}

else {

//echo "User Found";

//save session

//$_SESSION['id'] = $_POST['username'];

$response["success"] = 1;

$response["message"] = "Login successful!";

die(json_encode($response));

}

?>

and these are the errors i got..

02-25 23:49:41.824: E/AndroidRuntime(16061): FATAL EXCEPTION: AsyncTask #1

02-25 23:49:41.824: E/AndroidRuntime(16061): java.lang.RuntimeException: An error occured while executing doInBackground()

02-25 23:49:41.824: E/AndroidRuntime(16061): at android.os.AsyncTask$3.done(AsyncTask.java:299)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.FutureTask.run(FutureTask.java:137)

02-25 23:49:41.824: E/AndroidRuntime(16061): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.lang.Thread.run(Thread.java:856)

02-25 23:49:41.824: E/AndroidRuntime(16061): Caused by: java.lang.NullPointerException

02-25 23:49:41.824: E/AndroidRuntime(16061): at info.androidhive.slidingmenu.LoginPage$AttemptLogin.doInBackground(LoginPage.java:143)

02-25 23:49:41.824: E/AndroidRuntime(16061): at info.androidhive.slidingmenu.LoginPage$AttemptLogin.doInBackground(LoginPage.java:1)

02-25 23:49:41.824: E/AndroidRuntime(16061): at android.os.AsyncTask$2.call(AsyncTask.java:287)

02-25 23:49:41.824: E/AndroidRuntime(16061): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

02-25 23:49:41.824: E/AndroidRuntime(16061): ... 5 more

02-25 23:49:50.734: E/WindowManager(16061): Activity info.androidhive.slidingmenu.LoginPage has leaked window [email protected] that was originally added here

02-25 23:49:50.734: E/WindowManager(16061): android.view.WindowLeaked: Activity info.androidhive.slidingmenu.LoginPage has leaked window [email protected] that was originally added here

02-25 23:49:50.734: E/WindowManager(16061): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:321)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.Window$LocalWindowManager.addView(Window.java:559)

02-25 23:49:50.734: E/WindowManager(16061): at android.app.Dialog.show(Dialog.java:301)

02-25 23:49:50.734: E/WindowManager(16061): at info.androidhive.slidingmenu.LoginPage$AttemptLogin.onPreExecute(LoginPage.java:120)

02-25 23:49:50.734: E/WindowManager(16061): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)

02-25 23:49:50.734: E/WindowManager(16061): at android.os.AsyncTask.execute(AsyncTask.java:534)

02-25 23:49:50.734: E/WindowManager(16061): at info.androidhive.slidingmenu.LoginPage.onClick(LoginPage.java:89)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.View.performClick(View.java:4232)

02-25 23:49:50.734: E/WindowManager(16061): at android.view.View$PerformClick.run(View.java:17318)

02-25 23:49:50.734: E/WindowManager(16061): at android.os.Handler.handleCallback(Handler.java:615)

02-25 23:49:50.734: E/WindowManager(16061): at android.os.Handler.dispatchMessage(Handler.java:92)

02-25 23:49:50.734: E/WindowManager(16061): at android.os.Looper.loop(Looper.java:137)

02-25 23:49:50.734: E/WindowManager(16061): at android.app.ActivityThread.main(ActivityThread.java:4921)

02-25 23:49:50.734: E/WindowManager(16061): at java.lang.reflect.Method.invokeNative(Native Method)

02-25 23:49:50.734: E/WindowManager(16061): at java.lang.reflect.Method.invoke(Method.java:511)

02-25 23:49:50.734: E/WindowManager(16061): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)

02-25 23:49:50.734: E/WindowManager(16061): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)

02-25 23:49:50.734: E/WindowManager(16061): at dalvik.system.NativeStart.main(Native Method)

Please help me... :'(

网友答案:

I tried all the solutions posted above but it didnt work.. i finally resorted to uninstalling my xampp and reinstalling it again but it didnt work also.. but after 3 hours my app works again after closing and opening my eclipse for several times... i restarted my pc and run the app again to see if it works fine but it gives the same problem.. so i decided to search for problems related to my post.. and i found this blog strong text and tried to uninstall the adblock plus installed on all my browsers (mozilla firefox, google chrome, and opera) and it works fine.. :D

分享给朋友:
您可能感兴趣的文章:
随机阅读: