Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的StringRequest导致了一个null的截击错误_Php_Android_Networking_Android Volley - Fatal编程技术网

Php 我的StringRequest导致了一个null的截击错误

Php 我的StringRequest导致了一个null的截击错误,php,android,networking,android-volley,Php,Android,Networking,Android Volley,我花了几个小时调试这个问题,我觉得我真的很接近让它工作,但我就是不能找出这个错误。我知道我的URL是正确的,我的PHP代码是有效的。我通过将URL放入运行该应用程序的手机浏览器来验证这一点,它在生成的页面的HTML主体中向我返回了正确的JSON对象。此外,如果我将PHP代码设置为有错误(我未定义一个var),那么代码将显示该错误作为登录响应,并且截击不会出错 因此,我知道PHP代码返回一个有效响应,并且我正在与服务器建立有效连接,因此错误不存在。只要PHP有效,就会在收到PHP的响应之前出现截击

我花了几个小时调试这个问题,我觉得我真的很接近让它工作,但我就是不能找出这个错误。我知道我的URL是正确的,我的PHP代码是有效的。我通过将URL放入运行该应用程序的手机浏览器来验证这一点,它在生成的页面的HTML主体中向我返回了正确的JSON对象。此外,如果我将PHP代码设置为有错误(我未定义一个var),那么代码将显示该错误作为登录响应,并且截击不会出错

因此,我知道PHP代码返回一个有效响应,并且我正在与服务器建立有效连接,因此错误不存在。只要PHP有效,就会在收到PHP的响应之前出现截击错误。截击一定有问题,但我不知道是什么问题

其他可能有帮助的细节: -不管出于什么原因,它似乎要调用getParams()两次

下面是整个字符串请求、错误和应用程序单例的代码

以下是我的字符串请求的代码:
截击单例代码:
公共类AppSingleton{
私有静态AppSingleton mappsinglestation;
私有请求队列mRequestQueue;
私有静态上下文mContext;
私有AppSingleton(上下文){
mContext=上下文;
mRequestQueue=getRequestQueue();
}
公共静态同步AppSingleton getInstance(上下文){
if(mappsingletonistance==null){
mAppSingletonInstance=新AppSingleton(上下文);
}
返回mappsinglestation;
}
公共请求队列getRequestQueue(){
if(mRequestQueue==null){
//getApplicationContext()是关键,它可以防止泄漏
//活动或广播接收器(如果有人传入)。
mRequestQueue=Volley.newRequestQueue(mContext.getApplicationContext());
}
返回mrequest队列;
}
公共无效addToRequestQueue(请求请求,字符串标记){
要求设置标签(标签);
getRequestQueue().add(请求);
}
}

这是我的舱单:

private void loginUser( final String email, final String password) {
    // Tag used to cancel the request
    String cancel_req_tag = "login";
    progressDialog.setMessage("Logging you in...");
    showDialog();
    StringRequest strReq = new StringRequest(Request.Method.POST, URL_FOR_LOGIN, new Response.Listener<String>()
    {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Login Response: " + response);
            hideDialog();
            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");
                if (!error) {
                    String user = jObj.getJSONObject("user").getString("name");
                    // Launch User activity
                    Intent intent = new Intent(
                            LoginActivity.this,
                            UserActivity.class);
                    intent.putExtra("username", user);
                    startActivity(intent);
                    finish();
                } else {

                    String errorMsg = jObj.getString("error_msg");
                    Toast.makeText(getApplicationContext(),
                            errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Volley Error in login Activity: " + error.getMessage());
            for(int i = 0; i<error.getStackTrace().length; i++)
            {
                Log.e(TAG, "Class name for Stack Trace element " + i +": " + error.getStackTrace()[i].getClassName());
                Log.e(TAG, "File name for Stack Trace element " + i +": " + error.getStackTrace()[i].getFileName());
                Log.e(TAG, "Line Number for Stack Trace element " + i +": " + error.getStackTrace()[i].getLineNumber());
                Log.e(TAG, "Method name for Stack Trace element " + i +": " + error.getStackTrace()[i].getMethodName());
                Log.e(TAG, "Result from isNativeMethod " + i +": " + error.getStackTrace()[i].isNativeMethod());
            }

            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    })
    {
        @Override
        protected Map<String, String> getParams() {
            // Posting params to login url
            Map<String, String> params = new HashMap<String, String>();
            params.put("email", email);
            params.put("password", password);
            return params;
        }
    };
    // Adding request to request queue
    AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq,cancel_req_tag);
}
Class name for Stack Trace element 0: com.android.volley.toolbox.BasicNetwork
             File name for Stack Trace element 0: BasicNetwork.java
             Line Number for Stack Trace element 0: 173
             Method name for Stack Trace element 0: performRequest
             Result from isNativeMethod 0: false
Class name for Stack Trace element 1: com.android.volley.NetworkDispatcher
             File name for Stack Trace element 1: NetworkDispatcher.java
             Line Number for Stack Trace element 1: 131
             Method name for Stack Trace element 1: processRequest
             Result from isNativeMethod 1: false
Class name for Stack Trace element 2: com.android.volley.NetworkDispatcher
             File name for Stack Trace element 2: NetworkDispatcher.java
             Line Number for Stack Trace element 2: 111
             Method name for Stack Trace element 2: processRequest
             Result from isNativeMethod 2: false
Class name for Stack Trace element 3: com.android.volley.NetworkDispatcher
             File name for Stack Trace element 3: NetworkDispatcher.java
             Line Number for Stack Trace element 3: 90
             Method name for Stack Trace element 3: run
             Result from isNativeMethod 3: false
public class AppSingleton {
private static AppSingleton mAppSingletonInstance;
private RequestQueue mRequestQueue;
private static Context mContext;

private AppSingleton(Context context) {
    mContext = context;
    mRequestQueue = getRequestQueue();
}

public static synchronized AppSingleton getInstance(Context context) {
    if (mAppSingletonInstance == null) {
        mAppSingletonInstance = new AppSingleton(context);
    }
    return mAppSingletonInstance;
}

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
    }
    return mRequestQueue;
}

public <T> void addToRequestQueue(Request<T> req,String tag) {
    req.setTag(tag);
    getRequestQueue().add(req);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycallstracker.mycallstracker">
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">
    <activity android:name=".LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".RegisterActivity"/>
    <activity android:name=".UserActivity" />
</application>