OrderTab
public class Order_Tab extends Fragment{
Context context;
JSONObject Tokenobj=null;
String token;
String token_type;
String title;
String price;
String status;
String symbol;
String imageurl;
private ImageView imageOrdersN;
private ProgressDialog pDialog;
JSONParser jsonParser=new JSONParser();
private static final String URL_ORDERS="http://baymd.myterranet.com/api/orders/";
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.fragment_orders_tabs,container,false);
imageOrdersN= (ImageView) v.findViewById(R.id.imageOrders);
return v;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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>>();
new LoadOrders().execute();
}
public void parse(int counter){
try{
List<NameValuePair> param = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.makeHttpRequest(URL_ORDERS, "GET", param, token);
JSONObject name = new JSONObject();
JSONObject data = json.getJSONObject("data");
JSONObject orders = data.getJSONObject("orders");
JSONObject country = orders.getJSONObject("US");
Log.d("JSON NAME",name.toString());
Log.d("JSON ORDERS",orders.toString());
Log.d("JSON COUNTRY", country.toString());
for(;counter < 20;counter++) {
JSONObject c = country.getJSONObject(String.valueOf(counter));
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);
}
} catch (JSONException e){
e.printStackTrace();
parse(counter+1);
}
}
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) {
parse(19);
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);
return null;
}
@Override
protected void onPostExecute(String s) {
pDialog.dismiss();
ListView list= (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter=new SimpleAdapter(getActivity(),orderList,R.layout.fragment_order_list_item,
new String[]{TAG_PRICE,TAG_TITLE,TAG_PSTATUS,TAG_PRICESYMBOL,TAG_IMAGE},new int[]{R.id.price,R.id.title,R.id.pstatus,R.id.symbol,R.id.imageOrders});
Picasso.with(getView().getContext()).load(R.drawable.usa).into(imageOrdersN);
list.setAdapter(adapter);
}
}
}
logcat的
09-29 22:49:54.219 4416-4416/baymd.baymdfinal E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:479)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:462)
at baymd.baymdfinal.Order_Tab$LoadOrders.onPostExecute(Order_Tab.java:134)
at baymd.baymdfinal.Order_Tab$LoadOrders.onPostExecute(Order_Tab.java:100)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
来自Json的ImageLink
http://i.ebayimg.com/00/s/NzE2WDcxNg==/z/ObwAAOSwPe1T5ENW/$_12.JPG?set_id=8800005007
我已经知道问题出现在ImageView中,但我不知道如何修复它,相信我在网上寻找解决方案而我找不到,
如果需要其他材料,可以随意询问