android phpmyadmin,从android studio向phpmyadmin添加数据时出现问题 -尊龙游戏旗舰厅官网
我是安卓的初学者。 但是我在将android studio中的数据添加到phpmyadmin时遇到了问题。 我找到了一个准备好的代码,但是由于某种原因,当我点击按钮时,应用程序崩溃了。 我认为问题出在“networkcalls”上。<>如果我删除它,那么应用程序不会崩溃,但不会执行该功能。
activity:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.test.screenone">
android:id="@ id/etusername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputtype="textpersonname"
android:text="name"
android:layout_centerhorizontal="true"
android:layout_margintop="330dp"/>
android:id="@ id/etpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputtype="textpassword"
android:layout_centerhorizontal="true"
android:layout_margintop="400dp"/>
android:id="@ id/bsave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_centerhorizontal="true"
android:layout_margintop="600dp"
android:onclick="saveb"/>
maincode:package com.test.test;
import android.app.progressdialog;
import android.support.v7.app.appcompatactivity;
import android.os.bundle;
import android.view.view;
import android.view.window;
import android.widget.button;
import android.widget.edittext;
import android.widget.toast;
import com.android.volley.authfailureerror;
import com.android.volley.request;
import com.android.volley.response;
import com.android.volley.volleyerror;
import com.android.volley.toolbox.stringrequest;
import java.util.hashmap;
import java.util.map;
public class screenone extends appcompatactivity {
private static final string url_save = "http://ip/save.php";
private edittext username;
private edittext password;
button save;
string name;
string pass;
@override
protected void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.screen_one);
username = (edittext) findviewbyid(r.id.etusername);
password = (edittext) findviewbyid(r.id.etpassword);
save = (button) findviewbyid(r.id.bsave);
}
public void saveb(view view) {
saverequest();
}
private void saverequest() {
name = username.gettext().tostring().trim();
pass = password.gettext().tostring().trim();
final progressdialog mdialog = new progressdialog(this);
mdialog.requestwindowfeature(window.feature_no_title);
mdialog.setmessage("loading...");
mdialog.show();
stringrequest request = new stringrequest(request.method.post, url_save,
new response.listener() {
@override
public void onresponse(string response) {
mdialog.dismiss();
toast.maketext(screenone.this, response, toast.length_long).show();
username.settext("");
password.settext("");
}
},
new response.errorlistener() {
@override
public void onerrorresponse(volleyerror error) {
mdialog.dismiss();
toast.maketext(screenone.this, "something went wrong", toast.length_long).show();
}
}) {
@override
protected map getparams() throws authfailureerror {
map key = new hashmap<>();
key.put("username", name);
key.put("password", pass);
return key;
}
};
networkcalls.getinstance().addtorequestqueue(request);
}
}
网络呼叫:package com.test.test;
import android.content.context;
import com.android.volley.request;
import com.android.volley.requestqueue;
import com.android.volley.toolbox.volley;
public class networkcalls {
private requestqueue requestqueue;
private static context context;
private static networkcalls ourinstance = new networkcalls();
public static networkcalls getinstance() {
return ourinstance;
}
private networkcalls() {
}
public requestqueue getrequestqueue(){
requestqueue = volley.newrequestqueue(context.getapplicationcontext());
return requestqueue;
}
public void addtorequestqueue(request request){
getrequestqueue().add(request);
}
}
总结
以上是尊龙游戏旗舰厅官网为你收集整理的android phpmyadmin,从android studio向phpmyadmin添加数据时出现问题的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: 华为正式宣布鸿蒙,空欢喜一场?华为正式宣