开发的android应用程序无法连接到phpmyadmin

开发的android应用程序无法连接到phpmyadmin,第1张

概述我正在用 eclipse开发一个应用程序.我试图将用户键入的数据存储到phpmyadmin中的数据库中.不幸的是,在用户点击提交按钮后,没有响应,数据也没有存储在我的数据库中. 这是我的java文件: import java.util.ArrayList;import java.util.List;import org.apache.http.NameValuePair;import or 我正在用 eclipse开发一个应用程序.我试图将用户键入的数据存储到phpmyadmin中的数据库中.不幸的是,在用户点击提交按钮后,没有响应,数据也没有存储在我的数据库中.

这是我的java文件:

@H_301_13@import java.util.ArrayList;import java.util.List;import org.apache.http.nameValuePair;import org.apache.http.message.BasicnameValuePair;import org.Json.JsONObject;import androID.app.Activity;import androID.app.AlertDialog;import androID.content.DialogInterface;import androID.content.Intent;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Radiobutton;import androID.content.res.Configuration;public class UserRegister extends Activity {JsONParser JsonParser = new JsONParser();EditText inputname;EditText inputUsername;EditText inputEmail;EditText inputPassword;Radiobutton button1;Radiobutton button2;button button3;int success = 0;private static String url_register_user = "http://10.20.92.81/database/add_user.PHP";private static final String TAG_SUCCESS = "success";@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_user_register); inputname = (EditText) findVIEwByID(R.ID.nameTextBox); inputUsername = (EditText) findVIEwByID(R.ID.usernameTextBox); inputEmail = (EditText) findVIEwByID(R.ID.emailTextBox); inputPassword = (EditText) findVIEwByID(R.ID.pwTextBox); button button3 = (button) findVIEwByID(R.ID.regsubmitbutton); button3.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw vIEw) { String name = inputname.getText().toString(); String username = inputUsername.getText().toString(); String email = inputEmail.getText().toString(); String password = inputPassword.getText().toString(); if (name.contentEquals("")||username.contentEquals("")||email.contentEquals("")||password.contentEquals("")) { AlertDialog.Builder builder = new AlertDialog.Builder(UserRegister.this); builder.setMessage(R.string.nullAlert) .setTitle(R.string.alertTitle); builder.setPositivebutton(R.string.ok,new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { } }); AlertDialog dialog = builder.show(); } // creating new product in background thread RegisterNewUser(); } });} public voID RegisterNewUser() { try { String name = inputname.getText().toString(); String username = inputUsername.getText().toString(); String email = inputEmail.getText().toString(); String password = inputPassword.getText().toString(); // Building Parameters List<nameValuePair> params = new ArrayList<nameValuePair>(); params.add(new BasicnameValuePair("name",name)); params.add(new BasicnameValuePair("username",username)); params.add(new BasicnameValuePair("email",email)); params.add(new BasicnameValuePair("password",password)); // getting JsON Object // Note that create product url accepts POST method JsONObject Json = JsonParser.makehttpRequest(url_register_user,"GET",params); // check log cat for response Log.d("Send Notification",Json.toString()); success = Json.getInt(TAG_SUCCESS); if (success == 1) { // successfully created product Intent i = new Intent(getApplicationContext(),StudentLogin.class); startActivity(i); finish(); } else { // Failed to register } } catch (Exception e) { e.printstacktrace(); } } @OverrIDe public voID onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }}

我的PHP文件:

@H_301_13@<?PHP$response = array();require_once __DIR__ . '/db_connect.PHP';$db = new DB_CONNECT();if (isset($_GET['name']) && isset($_GET['username']) && isset($_GET['email']) && isset($_GET['password'])) {$name = $_GET['name'];$username = $_GET['username'];$email = $_GET['email'];$password = $_GET['password'];// MysqL inserting a new row$result = MysqL_query("INSERT INTO register(name,username,email,password) VALUES('$name','$username','$email','$password')");// check if row inserted or notif ($result) { // successfully inserted into database $response["success"] = 1; $response["message"] = "You are successfully registered to MEMS."; // echoing JsON response echo Json_encode($response);} else { // Failed to insert row $response["success"] = 0; $response["message"] = "Oops! An error occurred."; // echoing JsON response echo Json_encode($response);}} else {// required fIEld is missing$response["success"] = 0;$response["message"] = "required fIEld(s) is missing";// echoing JsON responseecho Json_encode($response);}?>

日志猫如下:

@H_301_13@11-25 10:37:46.772: I/Choreographer(638): Skipped 30 frames! The application may be doing too much work on its main thread.解决方法 首先,遵循Java命名约定并保持方法名称以小写字母开头.

其次,您必须获取networkonmainthreadException,因为您正在UI线程上执行阻止网络 *** 作.你做到了,你会度过一段美好的时光.

将所有网络代码放在异步任务中,或至少放在一个单独的线程中.

总结

以上是内存溢出为你收集整理的开发的android应用程序无法连接到phpmyadmin全部内容,希望文章能够帮你解决开发的android应用程序无法连接到phpmyadmin所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1124740.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存