欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 编程语言 > php >内容正文

php

android phpmyadmin,从android studio向phpmyadmin添加数据时出现问题 -凯发k8官方网

发布时间:2024/10/8 php 0 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 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);

}

}

总结

以上是凯发k8官方网为你收集整理的android phpmyadmin,从android studio向phpmyadmin添加数据时出现问题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图