当我点击产品ListView看产品datail有错误! 空指针异常
FragmentAllShop.java onClick listview项目将转到详细页面
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { int detailshop_id = model.getShop_id(); String shopID = String.valueOf(detailshop_id); Toast.makeText(FragmentAllShopping.this.getActivity(), "Select shopping_id: "+detailshop_id, Toast.LENGTH_SHORT).show(); Intent shopDetail = new Intent(getActivity(), ShoppingDetailActivity.class); shopDetail.putExtra("shopID", shopID); startActivity(shopDetail); }第89行代码中的ShoppingDetail.java错误 - > TitleShop.setText(model.getShop_title());
ShowImgProduct = (ImageView)findViewById(R.id.ShowImgProduct); TitleShop = (TextView)findViewById(R.id.TitleShop); TVPriceDetail = (TextView)findViewById(R.id.TVPriceDetail); DetailProduct = (TextView)findViewById(R.id.DetailProduct); TVuserPost = (TextView)findViewById(R.id.TVuserPost); show_shopdetail_id = getIntent().getStringExtra("shopID"); detailshop_id = Integer.parseInt(show_shopdetail_id); JSONParser jspaser = new JSONParser(); String url = "http://www.leveltistweb09.com/Hello_Oppa/get_shoppingdetail.php?shop_id="+detailshop_id; String dataJSON = jspaser.makeHttpRequest(url,JSONParser.methodGet, null); try { jsOBJ = new JSONObject(dataJSON); int shop_id = jsOBJ.getInt("shop_id"); String shop_img_url = jsOBJ.getString("shop_img_url"); String shop_title = jsOBJ.getString("shop_title"); String shop_price = "ราคา "+jsOBJ.getString("shop_price")+" บาท"; String shop_detail = jsOBJ.getString("shop_detail"); String user_display_name = "post by : "+jsOBJ.getString("user_display_name"); String shop_email = jsOBJ.getString("shop_email"); String shop_tel = jsOBJ.getString("shop_tel"); model = new AllShop_Model(shop_id, shop_img_url, shop_title, shop_price, shop_detail, user_display_name, shop_email, shop_tel); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } TitleShop.setText(model.getShop_title()); TVPriceDetail.setText(model.getShop_price()); DetailProduct.setText(model.getShop_detail()); TVuserPost.setText(model.getUser_display_name()); String path = "http://su13540254.2th.asia/Hello_Oppa/img/"; ShowImgProduct.setImageBitmap(loadBitmap(path+model.getShop_img_url())); }错误图片点击!! 第89行代码出错 - > TitleShop.setText(model.getShop_title());
when I click on product ListView to see product datail have error! NullPointerException
FragmentAllShop.java onClick listview item will go to detail page
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { int detailshop_id = model.getShop_id(); String shopID = String.valueOf(detailshop_id); Toast.makeText(FragmentAllShopping.this.getActivity(), "Select shopping_id: "+detailshop_id, Toast.LENGTH_SHORT).show(); Intent shopDetail = new Intent(getActivity(), ShoppingDetailActivity.class); shopDetail.putExtra("shopID", shopID); startActivity(shopDetail); }ShoppingDetail.java error on code at line 89 -> TitleShop.setText(model.getShop_title());
ShowImgProduct = (ImageView)findViewById(R.id.ShowImgProduct); TitleShop = (TextView)findViewById(R.id.TitleShop); TVPriceDetail = (TextView)findViewById(R.id.TVPriceDetail); DetailProduct = (TextView)findViewById(R.id.DetailProduct); TVuserPost = (TextView)findViewById(R.id.TVuserPost); show_shopdetail_id = getIntent().getStringExtra("shopID"); detailshop_id = Integer.parseInt(show_shopdetail_id); JSONParser jspaser = new JSONParser(); String url = "http://www.leveltistweb09.com/Hello_Oppa/get_shoppingdetail.php?shop_id="+detailshop_id; String dataJSON = jspaser.makeHttpRequest(url,JSONParser.methodGet, null); try { jsOBJ = new JSONObject(dataJSON); int shop_id = jsOBJ.getInt("shop_id"); String shop_img_url = jsOBJ.getString("shop_img_url"); String shop_title = jsOBJ.getString("shop_title"); String shop_price = "ราคา "+jsOBJ.getString("shop_price")+" บาท"; String shop_detail = jsOBJ.getString("shop_detail"); String user_display_name = "post by : "+jsOBJ.getString("user_display_name"); String shop_email = jsOBJ.getString("shop_email"); String shop_tel = jsOBJ.getString("shop_tel"); model = new AllShop_Model(shop_id, shop_img_url, shop_title, shop_price, shop_detail, user_display_name, shop_email, shop_tel); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } TitleShop.setText(model.getShop_title()); TVPriceDetail.setText(model.getShop_price()); DetailProduct.setText(model.getShop_detail()); TVuserPost.setText(model.getUser_display_name()); String path = "http://su13540254.2th.asia/Hello_Oppa/img/"; ShowImgProduct.setImageBitmap(loadBitmap(path+model.getShop_img_url())); }error image click!! error on code at line 89 -> TitleShop.setText(model.getShop_title());
最满意答案
- 首先,你必须检查你是否正确地得到Json响应 ,然后检查响应是否正确然后你存储在适当的对象中 ,即: - shop_title不是空检查这里。
- 让我知道如果问题存在更多谢谢
-First of All you have to check whether you are getting Json response properly or not and then check if response is right then you are storing in proper object or not i.e:- shop_title is not null check here.
-Let me know if issue exist more Thanks
更多推荐
发布评论