您好,我目前正在我们的Android项目工作..我的代码工作正常昨晚我去睡觉后...再次打开它..它甚至无法执行我的登录页面活动..
这是我的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();
}
}
}
}
`
这是我的PHP代码,因为我的代码连接到我的远程服务器..
<?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));
}
?>
这些是我得到的错误..
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 com.android.internal.policy.impl.PhoneWindow$DecorView@42156cd8 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 com.android.internal.policy.impl.PhoneWindow$DecorView@42156cd8 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)
请帮助我......:'(
答案 0 :(得分:0)
我尝试了上面发布的所有解决方案,但它没有工作..我终于使用卸载我的xampp并重新安装它但它也没有工作..但3小时后我的应用程序再次工作后关闭和打开我的日食几个时间...我重新启动我的电脑并再次运行应用程序,看它是否正常但它给出了同样的问题..所以我决定搜索与我的帖子相关的问题..我发现这个博客强文并尝试卸载我所有浏览器上安装的adblock plus(mozilla firefox,google chrome和opera),它运行正常..:D