无法启动活动错误:onCreate中的NullPointerException(Unable to start activity Error: NullPointerException in onCr

编程入门 行业动态 更新时间:2024-10-28 04:20:36
无法启动活动错误:onCreate中的NullPointerException(Unable to start activity Error: NullPointerException in onCreate)

当我点击产品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

更多推荐

本文发布于:2023-08-02 09:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1373239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法启动   错误   onCreate   NullPointerException   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!