Android Volley StringRequest无效

时间:2017-03-20 07:39:40

标签: php android mysql android-volley wampserver

大家好,我在使用凌空时遇到了问题。

此代码应该与我的wamp服务器中的php文件连接 我被要求全班,所以你去。

package info.androidhive.loginandregistration.activity;

import android.app.Activity;
import android.app.ProgressDialog;
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.Toast;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import info.androidhive.loginandregistration.R;
import info.androidhive.loginandregistration.app.AppConfig;
import info.androidhive.loginandregistration.app.AppController;
import info.androidhive.loginandregistration.helper.SQLiteHandler;
import info.androidhive.loginandregistration.helper.SessionManager;

public class RegisterActivity extends Activity {
    private static final String TAG = RegisterActivity.class.getSimpleName();
    private Button btnRegister;
    private Button btnLinkToLogin;
    private EditText inputFullName;
    private EditText inputEmail;
    private EditText inputPassword;
    private ProgressDialog pDialog;
    private SessionManager session;
    private SQLiteHandler db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        inputFullName = (EditText) findViewById(R.id.name);
        inputEmail = (EditText) findViewById(R.id.email);
        inputPassword = (EditText) findViewById(R.id.password);
        btnRegister = (Button) findViewById(R.id.btnRegister);
        btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);

        // Progress dialog
        pDialog = new ProgressDialog(this);
        pDialog.setCancelable(false);

        // Session manager
        session = new SessionManager(getApplicationContext());

        // SQLite database handler
        db = new SQLiteHandler(getApplicationContext());

        // Check if user is already logged in or not
        if (session.isLoggedIn()) {
            // User is already logged in. Take him to main activity
            Intent intent = new Intent(RegisterActivity.this,
                    MainActivity.class);
            startActivity(intent);
            finish();
        }

        // Register Button Click event
        btnRegister.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String name = inputFullName.getText().toString().trim();
                String email = inputEmail.getText().toString().trim();
                String password = inputPassword.getText().toString().trim();

                if (!name.isEmpty() && !email.isEmpty() && !password.isEmpty()) {
                    registerUser(name, email, password);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Please enter your details!", Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

        // Link to Login Screen
        btnLinkToLogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(),
                        LoginActivity.class);
                startActivity(i);
                finish();
            }
        });

    }

    /**
     * Function to store user in MySQL database will post params(tag, name,
     * email, password) to register url
     * */
    private void registerUser(final String name, final String email,
                              final String password) {
        Log.d(TAG, "Metodo Register user iniciado");
        // Tag used to cancel the request
        String tag_string_req = "req_register";

        pDialog.setMessage("Registering ...");
        showDialog();
        Log.d(TAG, "Metodo Register user Bandera1");
        StringRequest strReq = new StringRequest(Method.POST,AppConfig.URL_REGISTER, new Response.Listener<String>() {

            @Override

            public void onResponse(String response) {
                Log.d(TAG, "Metodo Register user Bandera2");
                Log.d(TAG, "Register Response: " + response.toString());
                hideDialog();

                try {
                    Log.d(TAG, "Metodo Register user Bandera3");
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");
                    if (!error) {
                        // User successfully stored in MySQL
                        // Now store the user in sqlite
                        String uid = jObj.getString("uid");

                        JSONObject user = jObj.getJSONObject("user");
                        String name = user.getString("name");
                        String email = user.getString("email");
                        String created_at = user
                                .getString("created_at");

                        // Inserting row in users table
                        db.addUser(name, email, uid, created_at);

                        Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();

                        // Launch login activity
                        Intent intent = new Intent(
                                RegisterActivity.this,
                                LoginActivity.class);
                        startActivity(intent);
                        finish();
                    } else {

                        // Error occurred in registration. Get the error
                        // message
                        String errorMsg = jObj.getString("error_msg");
                        Toast.makeText(getApplicationContext(),
                                errorMsg, Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    Log.d(TAG, "Error JSON"+e.toString());
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Registration Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_LONG).show();
                hideDialog();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                // Posting params to register url
                Map<String, String> params = new HashMap<String, String>();
                params.put("name", name);
                params.put("email", email);
                params.put("password", password);

                return params;
            }

        };

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
    }

    private void showDialog() {
        if (!pDialog.isShowing())
            pDialog.show();
    }

    private void hideDialog() {
        if (pDialog.isShowing())
            pDialog.dismiss();
    }
}

最后,它会在应用程序中返回一个空的Toast,而logcat会显示

  03-20 03:49:46.964 29537-29537/? I/art: Late-enabling -Xcheck:jni
03-20 03:49:47.101 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.323 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.377 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.459 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.516 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.571 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.631 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.714 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.803 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.869 29537-29537/? W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.938 29537-29537/info.androidhive.loginandregistration W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /system/framework/XposedBridge.jar --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xnorelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/app/info.androidhive.loginandregistration-1/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@info.androidhive.loginandregistration-1@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
03-20 03:49:47.940 29537-29537/info.androidhive.loginandregistration W/System: ClassLoader referenced unknown path: /data/app/info.androidhive.loginandregistration-1/lib/arm
03-20 03:49:47.999 29537-29537/info.androidhive.loginandregistration I/InstantRun: Starting Instant Run Server for info.androidhive.loginandregistration
03-20 03:49:48.080 29537-29621/info.androidhive.loginandregistration D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-20 03:49:48.137 29537-29621/info.androidhive.loginandregistration I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 09/02/15, 76f806e, Ibddc658e36
03-20 03:49:48.140 29537-29621/info.androidhive.loginandregistration I/OpenGLRenderer: Initialized EGL, version 1.4
03-20 03:49:56.580 29537-29537/info.androidhive.loginandregistration D/RegisterActivity: Metodo Register user iniciado
03-20 03:49:56.655 29537-29537/info.androidhive.loginandregistration D/RegisterActivity: Metodo Register user Bandera1
03-20 03:49:56.698 29537-29860/info.androidhive.loginandregistration W/System: ClassLoader referenced unknown path: /system/framework/tcmclient.jar
03-20 03:50:04.314 29537-29537/info.androidhive.loginandregistration E/RegisterActivity: Registration Error: null
03-20 03:50:04.339 29537-29537/info.androidhive.loginandregistration D/Volley: [1] Request.finish: 7647 ms: [ ] http://192.168.1.90/android_login_api/register.php 0x67692ab3 NORMAL 1

IP地址正确,服务器正在运行,我不知道错误在哪里。也许有些建议可以解决某些事情是否正常工作? 注册错误为null,这就是我所拥有的一切。你可以看到我放了一些日志消息,只有#34; Bandera1&#34;得到了显示。

0 个答案:

没有答案