gpt4 book ai didi

不幸的是,android 应用程序在从真实设备运行时停止了

转载 作者:行者123 更新时间:2023-11-30 23:18:18 25 4
gpt4 key购买 nike

您好,我已经制作了我的第一个 android 应用程序,它有一个网络服务可以使用 XAMPP 连接到我本地 PC 中的 mysql DB 我可以从 Android 模拟器完美地运行它,没有任何麻烦但我需要从我的真实设备上运行,但我遇到了与数据库的连接问题

到目前为止,我已经更改了文件中的 IP 地址,该文件包含 Web 服务的连接详细信息以及 eclipse 中的 userfunction.java(这个用于用户注册和登录功能)

在手机端,我的电脑使用 LAN,我的手机使用 connectify wireless 连接到同一连接

但是当我从我的真实设备上点击登录按钮时,我在我的 logcat 中得到了这个

05-18 12:19:40.600: E/SensorManager(13663): thread start
05-18 12:19:40.725: E/SpannableStringBuilder(13663): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-18 12:19:40.725: E/SpannableStringBuilder(13663): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
05-18 12:19:47.695: E/JSON Parser(13663): Error parsing data org.json.JSONException: End of input at character 0 of
05-18 12:19:47.700: E/AndroidRuntime(13663): FATAL EXCEPTION: main
05-18 12:19:47.700: E/AndroidRuntime(13663): java.lang.NullPointerException
05-18 12:19:47.700: E/AndroidRuntime(13663): at com.mohammed.watzIslam.LoginActivity$1.onClick(LoginActivity.java:62)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.view.View.performClick(View.java:4211)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.view.View$PerformClick.run(View.java:17267)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.os.Handler.handleCallback(Handler.java:615)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.os.Handler.dispatchMessage(Handler.java:92)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.os.Looper.loop(Looper.java:137)
05-18 12:19:47.700: E/AndroidRuntime(13663): at android.app.ActivityThread.main(ActivityThread.java:4898)
05-18 12:19:47.700: E/AndroidRuntime(13663): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 12:19:47.700: E/AndroidRuntime(13663): at java.lang.reflect.Method.invoke(Method.java:511)
05-18 12:19:47.700: E/AndroidRuntime(13663): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-18 12:19:47.700: E/AndroidRuntime(13663): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-18 12:19:47.700: E/AndroidRuntime(13663): at dalvik.system.NativeStart.main(Native Method)

这是userfunction.java,保存了用户reg的位置地址。并登录 webserives

\
public class UserFunctions {

private JSONParser jsonParser;

private static String loginURL = "http://xxxx:port#/android_login_api/";
private static String registerURL = "http://xxxx:port#/android_login_api/";

private static String login_tag = "login";
private static String register_tag = "register";

// constructor
public UserFunctions(){
jsonParser = new JSONParser();
}

/**
* function make Login Request
* @param email
* @param password
* */
public JSONObject loginUser(String email, String password){
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", login_tag));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
// return json
// Log.e("JSON", json.toString());
return json;
}

/**
* function make reg. Request
* @param name
* @param email
* @param password
* */
public JSONObject registerUser(String name, String password, String email){
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", register_tag));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));



// getting JSON Object
JSONObject json = jsonParser.getJSONFromUrl(registerURL, params);
// return json
return json;
}

/**
* Function get Login status
* */
public boolean isUserLoggedIn(Context context){
DatabaseHandler db = new DatabaseHandler(context);
int count = db.getRowCount();
if(count > 0){
// user logged in
return true;
}
return false;
}

/**
* Function to logout user
* Reset Database
* */
public boolean logoutUser(Context context){
DatabaseHandler db = new DatabaseHandler(context);
db.resetTables();
return true;
}

}

谁能指出任何错误或建议我一个解决方案

谢谢

最佳答案

添加这些包:

import android.app.ProgressDialog;
import android.os.AsyncTask;

声明json为类成员字段:

私有(private)JSONObject json;

替换 JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);有了这个:

new AsyncTask<Void, Void, Void>() {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(SplashActivity.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading, please wait...");
progressDialog.show();
}

@Override
protected Void doInBackground(Void... pms) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", login_tag));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
json = jsonParser.getJSONFromUrl(loginURL, params);
return null;
}
protected void onPostExecute(Void result) {
if(progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(json != null) {
Log.e("JSON", json.toString());
}
else {
Log.e("JSON", "JSON is NULL");
}
};
}.execute();

关于不幸的是,android 应用程序在从真实设备运行时停止了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16620718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com