com.android.volley.ServerError on Android studio



我的应用程序很简单,主活动只有4个按钮,去相关的活动,其他4个活动是查看,添加,更新和删除一个产品。我有一个名为AppController"我有我的连接'定义',这里是它的代码:


import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

//this is a singleton class where we initialize all volley core objects
public class AppController extends Application{
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
public static String baseUrl= "https://example.000webhostapp.com/";  
/** Not the actual link */
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getmInstance(){
return mInstance;
}
public RequestQueue getRequestQueue(){
if(mRequestQueue == null){
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req){
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag){
if(mRequestQueue != null){
mRequestQueue.cancelAll(tag);
}
}
} 

我已经确定我的服务器正在使用邮差工作,我添加了一个产品使用它,它工作。

我已经检查了其他帖子,无法将其与我的代码联系起来(我在android开发方面有点新手)

更新,我得到了它的工作与以下代码添加到我的AppController文件在最后(只是帮助某人可能需要它在未来)

public void onErrorResponse(VolleyError error) {
NetworkResponse response = error.networkResponse;
if (response != null && response.statusCode == 404) {
try {
String res = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
//use this json as you want
} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
e1.printStackTrace();
} catch (JSONException e2) {
// returned data is not JSONObject?
e2.printStackTrace();
}
}
}

相关内容

最新更新