Android : Authentication error: Unable to respond to any of these challenges: {}

on Monday, October 6, 2014


I've got this error ,when reloading form json into listview(the data at first is shown but when i press the button to reload listview 3 or 4 times it disapears and trows me this error, i searched the google ,and couldn't find a solution please help


at first reload of OrdersDe http://iceimg.com/5IJU2jKj/stack1


after 4 reloads it disapears http://iceimg.com/rIRskBgj/stack2


(i'm sorry i tried to make a video but had software problems)


Logcat error



W/DefaultRequestDirector﹕ Authentication error: Unable to respond to any of these challenges: {}
W/System.err﹕ org.json.JSONException: No value for data
W/System.err﹕ at org.json.JSONObject.get(JSONObject.java:354)
W/System.err﹕ at org.json.JSONObject.getJSONObject(JSONObject.java:573)
W/System.err﹕ at baymd.baymd.fragments.OrdersUSA$LoadOrders.doInBackground(OrdersUSA.java:89)
W/System.err﹕ at baymd.baymd.fragments.OrdersUSA$LoadOrders.doInBackground(OrdersUSA.java:73)
W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)


JSONParser



public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

public JSONParser() {

}

public JSONObject getJSONFromUrl(final String url) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
public void setHttpEntityIsRepeatable(boolean isRepeatable){

}
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params,String mToken) {
try {
// check for request method
if (method == "POST") {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();

is = httpEntity.getContent();

} else if (method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Bearer",mToken);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
httpEntity.isRepeatable();
is = httpEntity.getContent();
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;

}
}


Here is the class with the listView



public class OrdersUSA extends Fragment {
JSONObject Tokenobj = null;
String token;
String token_type;
String title;
String price;
String status;
String symbol;
String imageurl;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String URL_ORDERS = "http://baymd.myterranet.com/api/orders/us/";
private static final String TAG_IMAGE = "orderImage";
private static final String TAG_TITLE = "title";
private static final String TAG_PRICE = "price";
private static final String TAG_PRICESYMBOL = "symbol";
private static final String TAG_PSTATUS = "orderPaymentStatus";

ArrayList<HashMap<String, String>> orderList;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.orders_usa, container, false);
new LoadOrders().execute();
try {
Tokenobj = new JSONObject(getActivity().getIntent().getStringExtra("cjson"));
Log.d("JObject", Tokenobj.toString());
token = Tokenobj.getString("access_token");
token_type = Tokenobj.getString("token_type");
Log.d("Token", token);
} catch (JSONException e) {
e.printStackTrace();
}
orderList = new ArrayList<HashMap<String, String>>();
return v;

}

class LoadOrders extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading orders ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}

@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> param = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.makeHttpRequest(URL_ORDERS, "GET", param, token);
JSONObject data = json.getJSONObject("data");
JSONObject orders = data.getJSONObject("orders");

Log.d("JSON DATA", data.toString());
Log.d("JSON ORDERS", orders.toString());
Iterator<String> orderIterator = orders.keys();
while (orderIterator.hasNext()) {
JSONObject c = orders.getJSONObject(orderIterator.next());
imageurl = c.getString(TAG_IMAGE);
Log.d("IDK", imageurl);
title = c.getString(TAG_TITLE).substring(0, 20);
price = c.getString(TAG_PRICE);
status = c.getString(TAG_PSTATUS);
symbol = c.getString(TAG_PRICESYMBOL);

HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_TITLE, title);
map.put(TAG_PRICE, price);
map.put(TAG_PSTATUS, status);
map.put(TAG_PRICESYMBOL, symbol);
map.put(TAG_IMAGE, imageurl);
// adding HashList to ArrayList
orderList.add(map);

}
} catch (JSONException e) {
e.printStackTrace();

}


return null;
}
@Override
protected void onPostExecute(String s) {


pDialog.dismiss();
ListView list = (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter = new MyAdapter(getActivity(), orderList, R.layout.order_usa_row, new String[]{TAG_PRICE, TAG_TITLE, TAG_PSTATUS, TAG_PRICESYMBOL},
new int[]{R.id.price, R.id.title, R.id.pstatus, R.id.symbol});


list.setAdapter(adapter);
}
}




public class MyAdapter extends SimpleAdapter {

public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}

public View getView(int position, View convertView, ViewGroup parent) {
// here you let SimpleAdapter built the view normally.
View v = super.getView(position, convertView, parent);

// Then we get reference for Picasso
ImageView img = (ImageView) v.getTag();
if (img == null) {
img = (ImageView) v.findViewById(R.id.imageOrders);
}
// get the url from the data you passed to the `Map`
Object url = ((Map)getItem(position)).get(TAG_IMAGE);
String ol=url.toString();
// do Picasso
Picasso.with(v.getContext()).load(ol).into(img);

// return the view
return v;
}
}
}

0 comments:

Post a Comment