我正在开发一个 android 应用程序,用户将在其中将用户名和密码保存到数据库中,并将值保存在数据库中。用户下次来的时候可以登录而不是注册,所以那个时候用户输入的用户名和密码会与表中保存的数据进行核对,如果用户名和密码匹配,用户将被引导到下一个其他页面将显示错误消息。在我的情况下,注册过程运行良好并且在登录过程中。执行该过程时不起作用。我正在添加用于将数据库与应用程序和 logcat 连接的活动和 php 文件。请检查这个,如果有任何错误请帮助我解决它。谢谢。
活动
public class SignInActivity extends Activity
{
/*LoginDataBaseAdapter loginDataBaseAdapter;*/
Button btnsignin;
String name,password, psw;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
// single product url
private static final String url_get_name = "http://iascpl.com/app/get_name_details.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCT = "product";
private static final String TAG_PASSWORD = "password";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.signin_xm);
/*loginDataBaseAdapter=new LoginDataBaseAdapter(this);
loginDataBaseAdapter=loginDataBaseAdapter.open();*/
btnsignin = (Button) findViewById ( R.id.button401);
btnsignin.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new GetNameDetails().execute();
}
});
}
class GetNameDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SignInActivity.this);
pDialog.setMessage("Loading the result... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product details in background thread
* */
protected String doInBackground(String... args)
{
final EditText et1 = (EditText) findViewById (R.id.editText401);
final EditText et2 = (EditText) findViewById (R.id.editText402);
name =et1.getText().toString();
password = et2.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_get_name, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_PRODUCT); // JSON Array
// get first product object from JSON Array
final JSONObject product = productObj.getJSONObject(0);
// product with this pid found
// Edit Text
runOnUiThread(new Runnable() {
@Override
public void run()
{
// TODO Auto-generated method stub
try {
psw = product.getString(TAG_PASSWORD);
if (password == psw);
{
Toast.makeText(SignInActivity.this, "Login Successfull", Toast.LENGTH_LONG).show();
Intent i = new Intent(SignInActivity.this,HomePageActivity.class);
startActivity(i);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}else{
// product with pid not found
}
} 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 got all details
pDialog.dismiss();
}
}
}
PHP
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["name"])) {
$name = $_GET['name'];
// get a product from products table
$result = mysql_query("SELECT *FROM numerol WHERE name = $name");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["name"] = $result["name"];
$product["passwordr"] = $result["password"];
// $product["price"] = $result["price"];
//$product["description"] = $result["description"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
日志猫
11-09 09:18:01.930: E/Trace(5068): error opening trace file: No such file or directory (2)
11-09 09:18:04.410: D/gralloc_goldfish(5068): Emulator without GPU emulation detected.
11-09 09:18:09.303: D/dalvikvm(5068): GC_CONCURRENT freed 83K, 7% free 2712K/2916K, paused 74ms+98ms, total 704ms
11-09 09:18:11.200: I/Choreographer(5068): Skipped 88 frames! The application may be doing too much work on its main thread.
11-09 09:18:20.180: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:23.910: D/dalvikvm(5068): GC_FOR_ALLOC freed 54K, 6% free 2872K/3048K, paused 61ms, total 82ms
11-09 09:18:23.931: I/dalvikvm-heap(5068): Grow heap (frag case) to 3.526MB for 635812-byte allocation
11-09 09:18:24.101: D/dalvikvm(5068): GC_FOR_ALLOC freed 2K, 5% free 3490K/3672K, paused 165ms, total 165ms
11-09 09:18:24.341: D/dalvikvm(5068): GC_CONCURRENT freed 2K, 5% free 3501K/3672K, paused 32ms+95ms, total 242ms
11-09 09:18:24.841: I/Choreographer(5068): Skipped 72 frames! The application may be doing too much work on its main thread.
11-09 09:18:25.690: I/Choreographer(5068): Skipped 83 frames! The application may be doing too much work on its main thread.
11-09 09:18:26.030: I/Choreographer(5068): Skipped 60 frames! The application may be doing too much work on its main thread.
11-09 09:18:26.860: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:28.152: I/Choreographer(5068): Skipped 71 frames! The application may be doing too much work on its main thread.
11-09 09:18:29.102: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:18:30.110: I/Choreographer(5068): Skipped 44 frames! The application may be doing too much work on its main thread.
11-09 09:18:30.522: I/Choreographer(5068): Skipped 34 frames! The application may be doing too much work on its main thread.
11-09 09:18:31.310: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:33.371: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:33.580: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:18:37.130: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:18:37.562: I/Choreographer(5068): Skipped 33 frames! The application may be doing too much work on its main thread.
11-09 09:18:39.361: I/Choreographer(5068): Skipped 45 frames! The application may be doing too much work on its main thread.
11-09 09:18:39.500: I/Choreographer(5068): Skipped 37 frames! The application may be doing too much work on its main thread.
11-09 09:18:41.312: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:44.911: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:18:45.660: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:18:47.970: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:50.081: I/Choreographer(5068): Skipped 39 frames! The application may be doing too much work on its main thread.
11-09 09:18:51.350: I/Choreographer(5068): Skipped 38 frames! The application may be doing too much work on its main thread.
11-09 09:18:51.720: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:19:12.970: I/Choreographer(5068): Skipped 85 frames! The application may be doing too much work on its main thread.
11-09 09:19:13.170: I/Choreographer(5068): Skipped 43 frames! The application may be doing too much work on its main thread.
11-09 09:19:18.532: I/Choreographer(5068): Skipped 42 frames! The application may be doing too much work on its main thread.
11-09 09:19:18.740: I/Choreographer(5068): Skipped 47 frames! The application may be doing too much work on its main thread.
11-09 09:19:24.440: I/Choreographer(5068): Skipped 76 frames! The application may be doing too much work on its main thread.
11-09 09:19:24.630: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:19:25.001: I/Choreographer(5068): Skipped 51 frames! The application may be doing too much work on its main thread.
11-09 09:19:25.610: I/Choreographer(5068): Skipped 146 frames! The application may be doing too much work on its main thread.
11-09 09:19:26.520: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:27.412: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:28.701: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:19:51.432: I/Choreographer(5068): Skipped 54 frames! The application may be doing too much work on its main thread.
11-09 09:19:53.631: D/dalvikvm(5068): GC_CONCURRENT freed 166K, 8% free 3740K/4028K, paused 74ms+101ms, total 332ms
11-09 09:19:54.360: I/Choreographer(5068): Skipped 112 frames! The application may be doing too much work on its main thread.
11-09 09:19:54.560: I/Choreographer(5068): Skipped 33 frames! The application may be doing too much work on its main thread.
11-09 09:19:55.591: I/Choreographer(5068): Skipped 195 frames! The application may be doing too much work on its main thread.
11-09 09:19:55.921: I/Choreographer(5068): Skipped 80 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.150: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.562: I/Choreographer(5068): Skipped 46 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.831: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.955: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:57.471: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:19:57.662: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:19:58.100: I/Choreographer(5068): Skipped 41 frames! The application may be doing too much work on its main thread.
11-09 09:19:58.350: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:19:59.010: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:59.661: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:20:46.300: I/Choreographer(5068): Skipped 35 frames! The application may be doing too much work on its main thread.
11-09 09:23:11.740: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:25:55.341: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:26:51.270: I/Choreographer(5068): Skipped 38 frames! The application may be doing too much work on its main thread.
11-09 09:27:01.220: I/Choreographer(5068): Skipped 58 frames! The application may be doing too much work on its main thread.
11-09 09:28:31.342: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:29:01.193: I/Choreographer(5068): Skipped 37 frames! The application may be doing too much work on its main thread.