我尝试了很多不同的IP地址以及使用127.0.0.0和我自己的计算机IP地址,但是当我运行我的程序并尝试注册它时,请联系服务器,然后它突然停止并且它说应用程序名字已停止工作。请你帮助我或帮助我,因为我已经坚持这个问题三天了。
我在wamp / www /文件夹中创建了一个名为bradvisor_login_api的文件夹,该文件夹有三个文件,其中一个文件用于我在下面列出的config.php文件。 phpMyAdmin帐户没有密码,只有root用户名。
有没有人可以帮我解决这个问题,我已经粘贴了我的config.php文件和一些我显示连接的java文件。
Config.PHP文件
<?php
/**
* Database config variables
*/
define("DB_HOST", "127.0.0.1");
define("DB_USER", "root");
define("DB_PASSWORD", "root");
define("DB_DATABASE", "bradvisor_login_api");
?>
Java连接文件
//URL of the PHP API
private static String loginURL = "http://192.168.0.8:80/bradvisor_login_api/";
private static String registerURL = "http://192.168.0.8:80/bradvisor_login_api/";
private static String forpassURL = "http://192.168.0.8:80/bradvisor_login_api/";
private static String chgpassURL = "http://192.168.0.8:80/bradvisor_login_api/";
httpd.conf文件
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
错误Logcat
07-02 20:02:42.163 2269-2526/com.brad.visor E/Buffer Error﹕ Error converting result java.lang.NullPointerException: lock == null
07-02 20:02:42.163 2269-2526/com.brad.visor E/JSON Parser﹕ Error parsing data org.json.JSONException: End of input at character 0 of
07-02 20:02:42.194 2269-2269/com.brad.visor E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.brad.visor, PID: 2269
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.getString(java.lang.String)' on a null object reference
at com.brad.visor.Register$ProcessRegister.onPostExecute(Register.java:232)
at com.brad.visor.Register$ProcessRegister.onPostExecute(Register.java:189)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Register.java文件:
private class ProcessRegister extends AsyncTask<String, String, JSONObject>
------------------------------------------------------------------------
{
/**
* Defining Process dialog
**/
private ProgressDialog pDialog;
String email,password,fname,lname,uname;
@Override
protected void onPreExecute() {
super.onPreExecute();
inputUsername = (EditText) findViewById(R.id.uname);
inputPassword = (EditText) findViewById(R.id.pword);
fname = inputFirstName.getText().toString();
lname = inputLastName.getText().toString();
email = inputEmail.getText().toString();
uname= inputUsername.getText().toString();
password = inputPassword.getText().toString();
pDialog = new ProgressDialog(Register.this);
pDialog.setTitle("Contacting Servers");
pDialog.setMessage("Registering ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(fname, lname, email, uname, password);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
/**
* Checks for success message.
**/
try {
if (json.getString(KEY_SUCCESS) != null) {
------------------------------------------
registerErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
String red = json.getString(KEY_ERROR);
if(Integer.parseInt(res) == 1){
pDialog.setTitle("Getting Data");
pDialog.setMessage("Loading Info");
registerErrorMsg.setText("Successfully Registered");
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
/**
* Removes all the previous data in the SQlite database
**/
UserFunctions logout = new UserFunctions();
logout.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_FIRSTNAME),json_user.getString(KEY_LASTNAME),json_user.getString(KEY_EMAIL),json_user.getString(KEY_USERNAME),json_user.getString(KEY_UID),json_user.getString(KEY_CREATED_AT));
/**
* Stores registered data in SQlite Database
* Launch Registered screen
**/
Intent registered = new Intent(getApplicationContext(), Registered.class);
/**
* Close all views before launching Registered screen
**/
registered.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pDialog.dismiss();
startActivity(registered);
finish();
}
else if (Integer.parseInt(red) ==2){
pDialog.dismiss();
registerErrorMsg.setText("User already exists");
}
else if (Integer.parseInt(red) ==3){
pDialog.dismiss();
registerErrorMsg.setText("Invalid Email id");
}
}
else{
pDialog.dismiss();
registerErrorMsg.setText("Error occured in registration");
}
} catch (JSONException e) {
e.printStackTrace();
}
}}
public void NetAsync(View view){
new NetCheck().execute();
}}
答案 0 :(得分:0)
从您的错误日志中: “值&lt; br的java.lang.String类型无法转换为JSONObject” 您要求的页面是什么,可以在问题中发布其内容。
据我所知,从错误日志中可以看出输入是不可解析的。当您收到HTML响应(其中breakrow是&lt; br /&gt;指示符,但在字符串上,它们可能是几个,例如\ 0)时,似乎就是这种情况。 似乎在解析时,内容被读作单个变量,并且无法缓冲变量中的整个响应,然后,失败的对象变为null,并对其进行操作。 (因此失败,并获得记录的错误)
答案 1 :(得分:0)
在Android Studio中,您必须将10.0.2.2作为IP。这是ip Android Studio用于localhost连接的。