- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 android 中开发一个项目,该项目使用 json 从 web 服务获取数据并显示在 ListView 中。
我解析了数据,并在模拟器中运行应用程序时强制关闭。
我做错了什么?更正将不胜感激。
这是我的完整代码
public class AndroidJSONParsingActivity extends ListActivity {
// url to make request
private static String url = "http://example.com/";
// JSON Node names
private static final String TAG_PRODUCT = "Product";
private static final String TAG_ID = "shop_prdt_id";
private static final String TAG_CATID="shop_cat_id";
private static final String TAG_SCATID="shop_scat_id";
private static final String TAG_PRODCODE="shop_prdt_code";
private static final String TAG_TITLE="shop_prdt_title";
private static final String TAG_LISTPRICE = "shop_prdt_listprice";
private static final String TAG_OURPRICE = "shop_prdt_ourprice";
private static final String TAG_YOU = "shop_prdt_yousave";
private static final String TAG_STOCK = "shop_prdt_stock";
private static final String TAG_WEIGHT = "shop_prdt_weight";
private static final String TAG_WEIGHTMEASURE = "shop_prdt_weight_measurement";
private static final String TAG_PRODCOLOR = "shop_prdt_color";
private static final String TAG_SIZE = "shop_prdt_size";
private static final String TAG_SPLDESC = "shop_prdt_spl_description";
private static final String TAG_DESC = "shop_prdt_description";
private static final String TAG_FEATURE="shop_prdt_featured";
private static final String TAG_SEOTITLE="shop_prdt_seo_title";
private static final String TAG_SEODESC="shop_prdt_seo_desc";
private static final String TAG_SEOKEYWORDS="shop_prdt_seo_keywords";
private static final String TAG_IMAGES="shop_prdt_images";
private static final String TAG_CLICKS="shop_prdt_clicks";
private static final String TAG_CREATEDATE="shop_prdt_createdon";
private static final String TAG_UPDATEDATE="shop_prdt_updatedon";
private static final String TAG_STATUS="shop_prdt_status";
// contacts JSONArray
JSONArray product = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
product = json.getJSONArray(TAG_PRODUCT);
// looping through All product
for(int i = 0; i < product.length(); i++){
JSONObject c = product.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_ID);
String catid = c.getString(TAG_CATID);
String Subcatid=c.getString(TAG_SCATID);
String prcode =c.getString(TAG_PRODCODE);
String title = c.getString(TAG_TITLE);
String listprice =c.getString(TAG_LISTPRICE);
String ourprice = c.getString(TAG_OURPRICE);
String you=c.getString(TAG_YOU);
String stock =c.getString(TAG_STOCK);
String weight =c.getString(TAG_WEIGHT);
String weightmes =c.getString(TAG_WEIGHTMEASURE);
String color =c.getString(TAG_PRODCOLOR);
String size =c.getString(TAG_SIZE);
String spldesc =c.getString(TAG_SPLDESC);
String desc =c.getString(TAG_DESC);
String feature =c.getString(TAG_FEATURE);
String seotitle=c.getString(TAG_SEOTITLE);
String seodesc =c.getString(TAG_SEODESC);
String seokeywords =c.getString(TAG_SEOKEYWORDS);
String images =c.getString(TAG_IMAGES);
String clicks =c.getString(TAG_CLICKS);
String createdate =c.getString(TAG_CREATEDATE);
String updatedate =c.getString(TAG_UPDATEDATE);
String status =c.getString(TAG_STATUS);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, id);
map.put(TAG_TITLE, title);
map.put(TAG_OURPRICE, ourprice);
map.put(TAG_YOU, you);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_TITLE, TAG_OURPRICE, TAG_YOU }, new int[] {
R.id.name, R.id.email, R.id.mobile });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String name1 = ((TextView) view.findViewById(R.id.name)).getText().toString();
String ourprice1 = ((TextView) view.findViewById(R.id.email)).getText().toString();
String you1 = ((TextView) view.findViewById(R.id.mobile)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(TAG_TITLE, name1);
in.putExtra(TAG_OURPRICE, ourprice1);
in.putExtra(TAG_YOU, you1);
startActivity(in);
}
});
}
}
我的json文件
{
"Product": [
{
"shop_prdt_id": "11",
"shop_cat_id": "3",
"shop_scat_id": "0",
"shop_prdt_code": "06PTPL-01PK",
"shop_prdt_title": "Party Wear Anarkkali Suits",
"shop_prdt_listprice": "44",
"shop_prdt_ourprice": "40",
"shop_prdt_yousave": "4",
"shop_prdt_stock": "20",
"shop_prdt_weight": "17.67",
"shop_prdt_weight_measurement": "GRM",
"shop_prdt_color": "3,4,7,8,12,13,14",
"shop_prdt_size": "3,5,11,13",
"shop_prdt_spl_description": "",
"shop_prdt_description": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur bibendum ornare dolor, quis ullamcorper ligula sodales at. Nulla tellus elit, varius non commodo eget, mattis vel eros. In sed ornare nulla.</p>\r\n\r\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur bibendum ornare dolor, quis ullamcorper ligula sodales at. Nulla tellus elit, varius non commodo eget, mattis vel eros. In sed ornare nulla.</p>\r\n",
"shop_prdt_featured": "1",
"shop_prdt_seo_title": "Party Wear Anarkkali Suits",
"shop_prdt_seo_desc": "Party Wear Anarkkali Suits",
"shop_prdt_seo_keywords": "Anarkkali Suits",
"shop_prdt_images": "1",
"shop_prdt_clicks": "13",
"shop_prdt_createdon": "2013-10-29 02:26:08",
"shop_prdt_updatedon": "2013-11-17 17:27:37",
"shop_prdt_status": "1"
},
{
"shop_prdt_id": "8",
"shop_cat_id": "2",
"shop_scat_id": "0",
"shop_prdt_code": "SKCT-28",
"shop_prdt_title": "Pure Silk Cotton",
"shop_prdt_listprice": "150",
"shop_prdt_ourprice": "120",
"shop_prdt_yousave": "30",
"shop_prdt_stock": "30",
"shop_prdt_weight": "35",
"shop_prdt_weight_measurement": "GRM",
"shop_prdt_color": "25",
"shop_prdt_size": "",
"shop_prdt_spl_description": "<p><span class="fbPhotosPhotoCaption" data-ft="{&quot;type&quot;:45,&quot;tn&quot;:&quot;*G&quot;}" id="fbPhotoSnowliftCaption" tabindex="0"><span class="hasCaption">Women and pink ? Perfect combination ! Beautiful bright pink with vibrant coloured threadwork design on it, for a truly classy feel. For the woman who quietly walks into the room and takes everyone&#39;s breath away</span></span></p>\r\n",
"shop_prdt_description": "<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of &quot;de Finibus Bonorum et Malorum&quot; (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, &quot;Lorem ipsum dolor sit amet..&quot;, comes from a line in section 1.10.32.</p>\r\n\r\n<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from &quot;de Finibus Bonorum et Malorum&quot; by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>\r\n",
"shop_prdt_featured": "1",
"shop_prdt_seo_title": "Pure Silk Cotton",
"shop_prdt_seo_desc": "For the woman who quietly walks into the room and takes everyone's breath away.",
"shop_prdt_seo_keywords": "Pure Silk Cotton, Cotton, Sharani Designs",
"shop_prdt_images": "1",
"shop_prdt_clicks": "13",
"shop_prdt_createdon": "2013-10-09 22:15:05",
"shop_prdt_updatedon": "",
"shop_prdt_status": "1"
},
{
"shop_prdt_id": "7",
"shop_cat_id": "1",
"shop_scat_id": "3",
"shop_prdt_code": "PTD-08GR",
"shop_prdt_title": "House Wears with simple colors",
"shop_prdt_listprice": "15",
"shop_prdt_ourprice": "13.90",
"shop_prdt_yousave": "1.1",
"shop_prdt_stock": "25",
"shop_prdt_weight": "11",
"shop_prdt_weight_measurement": "GRM",
"shop_prdt_color": "3,8,10",
"shop_prdt_size": "1,2,3,5,7,9,11",
"shop_prdt_spl_description": "<p>&nbsp;If you are going to use a passage of Lorem Ipsum, you need to be sure there isn&#39;t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.</p>\r\n",
"shop_prdt_description": "<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don&#39;t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn&#39;t anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>\r\n\r\n<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of &quot;de Finibus Bonorum et Malorum&quot; (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, &quot;Lorem ipsum dolor sit amet..&quot;, comes from a line in section 1.10.32.</p>\r\n\r\n<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from &quot;de Finibus Bonorum et Malorum&quot; by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>\r\n",
"shop_prdt_featured": "1",
"shop_prdt_seo_title": "House Wears with simple colors",
"shop_prdt_seo_desc": "This book is a treatise on the theory of ethics, very popular during the Renaissance",
"shop_prdt_seo_keywords": "Sharani Designs",
"shop_prdt_images": "1",
"shop_prdt_clicks": "39",
"shop_prdt_createdon": "2013-10-09 21:48:51",
"shop_prdt_updatedon": "2013-11-16 23:58:07",
"shop_prdt_status": "1"
}
]
}
02-05 05:11:37.413: D/dalvikvm(2110): GC_FOR_ALLOC freed 217K, 9% free 2968K/3260K, paused 26ms, total 28ms
02-05 05:11:37.533: E/JSON Parser(2110): Error parsing data org.json.JSONException: Unterminated object at character 8276 of {
02-05 05:11:37.533: E/JSON Parser(2110): "Product":[
02-05 05:11:37.533: E/JSON Parser(2110): {
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_id":"11",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_cat_id":"3",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_scat_id":"0",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_code":"06PTPL-01PK",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_title":"Party Wear Anarkkali Suits",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_listprice":"44",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_ourprice":"40",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_yousave":"4",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_stock":"20",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight":"17.67",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight_measurement":"GRM",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_color":"3,4,7,8,12,13,14",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_size":"3,5,11,13",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_spl_description":"",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_description":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur bibendum ornare dolor, quis ullamcorper ligula sodales at. Nulla tellus elit, varius non commodo eget, mattis vel eros. In sed ornare nulla.<\/p>\r\n\r\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur bibendum ornare dolor, quis ullamcorper ligula sodales at. Nulla tellus elit, varius non commodo eget, mattis vel eros. In sed ornare nulla.<\/p>\r\n",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_featured":"1",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_title":"Party Wear Anarkkali Suits",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_desc":"Party Wear Anarkkali Suits",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_keywords":"Anarkkali Suits",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_images":"1",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_clicks":"13",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_createdon":"2013-10-29 02:26:08",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_updatedon":"2013-11-17 17:27:37",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_status":"1"
02-05 05:11:37.533: E/JSON Parser(2110): },
02-05 05:11:37.533: E/JSON Parser(2110): {
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_id":"10",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_cat_id":"4",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_scat_id":"0",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_code":"LEGG-GR01",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_title":"Premium Cotton Leggins",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_listprice":"15",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_ourprice":"13.90",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_yousave":"1.1",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_stock":"75",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight":"11",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight_measurement":"GRM",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_color":"9,12,23,26,27,28,29,36",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_size":"",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_spl_description":"<p><span class="fbPhotosPhotoCaption" data-ft="{&quot;type&quot;:45,&quot;tn&quot;:&quot;*G&quot;}" id="fbPhotoSnowliftCaption" tabindex="0"><span class="hasCaption">SLIGHT COLOUR VARIATIONS POSSIBLE DUE TO PHOTOGRAPHIC LIMITATIONS.<\/span><\/span><\/p>\r\n",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_description":"<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of &quot;de Finibus Bonorum et Malorum&quot; (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, &quot;Lorem ipsum dolor sit amet..&quot;, comes from a line in section 1.10.32.<\/p>\r\n\r\n<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from &quot;de Finibus Bonorum et Malorum&quot; by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.<\/p>\r\n",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_featured":"1",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_title":"Premium Cotton Leggins",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_desc":"96% Premium Cotton and 4% Spandex",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_seo_keywords":"Premium Cotton Leggins, cotton, sharani designs",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_images":"1",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_clicks":"84",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_createdon":"2013-10-09 22:23:56",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_updatedon":"",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_status":"1"
02-05 05:11:37.533: E/JSON Parser(2110): },
02-05 05:11:37.533: E/JSON Parser(2110): {
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_id":"9",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_cat_id":"2",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_scat_id":"0",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_code":"SKCT-38",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_title":"Pure Silk Cotton",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_listprice":"195",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_ourprice":"150",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_yousave":"45",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_stock":"34",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight":"110",
02-05 05:11:37.533: E/JSON Parser(2110): "shop_prdt_weight
02-05 05:11:37.543: D/AndroidRuntime(2110): Shutting down VM
02-05 05:11:37.543: W/dalvikvm(2110): threadid=1: thread exiting with uncaught exception (group=0xb4a4ab90)
02-05 05:11:37.573: E/AndroidRuntime(2110): FATAL EXCEPTION: main
02-05 05:11:37.573: E/AndroidRuntime(2110): Process: com.androidhive.jsonparsing, PID: 2110
02-05 05:11:37.573: E/AndroidRuntime(2110): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: java.lang.NullPointerException
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread.access$700(ActivityThread.java:135)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.os.Looper.loop(Looper.java:137)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread.main(ActivityThread.java:4998)
02-05 05:11:37.573: E/AndroidRuntime(2110): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 05:11:37.573: E/AndroidRuntime(2110): at java.lang.reflect.Method.invoke(Method.java:515)
02-05 05:11:37.573: E/AndroidRuntime(2110): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
02-05 05:11:37.573: E/AndroidRuntime(2110): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
02-05 05:11:37.573: E/AndroidRuntime(2110): at dalvik.system.NativeStart.main(Native Method)
02-05 05:11:37.573: E/AndroidRuntime(2110): Caused by: java.lang.NullPointerException
02-05 05:11:37.573: E/AndroidRuntime(2110): at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:73)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.Activity.performCreate(Activity.java:5243)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-05 05:11:37.573: E/AndroidRuntime(2110): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
02-05 05:11:37.573: E/AndroidRuntime(2110): ... 11 more
02-05 05:11:39.853: I/Process(2110): Sending signal. PID: 2110 SIG: 9
02-05 05:35:06.173: D/AndroidRuntime(2165): Shutting down VM
02-05 05:35:06.173: W/dalvikvm(2165): threadid=1: thread exiting with uncaught exception (group=0xb4a4ab90)
02-05 05:35:06.183: E/AndroidRuntime(2165): FATAL EXCEPTION: main
02-05 05:35:06.183: E/AndroidRuntime(2165): Process: com.androidhive.jsonparsing, PID: 2165
02-05 05:35:06.183: E/AndroidRuntime(2165): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: java.lang.IllegalArgumentException: Host name may not be null
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread.access$700(ActivityThread.java:135)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.os.Looper.loop(Looper.java:137)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread.main(ActivityThread.java:4998)
02-05 05:35:06.183: E/AndroidRuntime(2165): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 05:35:06.183: E/AndroidRuntime(2165): at java.lang.reflect.Method.invoke(Method.java:515)
02-05 05:35:06.183: E/AndroidRuntime(2165): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
02-05 05:35:06.183: E/AndroidRuntime(2165): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
02-05 05:35:06.183: E/AndroidRuntime(2165): at dalvik.system.NativeStart.main(Native Method)
02-05 05:35:06.183: E/AndroidRuntime(2165): Caused by: java.lang.IllegalArgumentException: Host name may not be null
02-05 05:35:06.183: E/AndroidRuntime(2165): at org.apache.http.HttpHost.<init>(HttpHost.java:83)
02-05 05:35:06.183: E/AndroidRuntime(2165): at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497)
02-05 05:35:06.183: E/AndroidRuntime(2165): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-05 05:35:06.183: E/AndroidRuntime(2165): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-05 05:35:06.183: E/AndroidRuntime(2165): at com.androidhive.jsonparsing.JSONParser.getJSONFromUrl(JSONParser.java:38)
02-05 05:35:06.183: E/AndroidRuntime(2165): at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:69)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.Activity.performCreate(Activity.java:5243)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-05 05:35:06.183: E/AndroidRuntime(2165): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
02-05 05:35:06.183: E/AndroidRuntime(2165): ... 11 more
02-05 05:35:07.913: I/Process(2165): Sending signal. PID: 2165 SIG: 9
最佳答案
您的 JSON 文件附近有错误
"shop_prdt_images": "1""shop_prdt_clicks": "13",
应该是
"shop_prdt_images": "1",
"shop_prdt_clicks": "13",
关于android - 我的项目中的 Json 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21574177/
最近开始学习MongoDB。今天老师教了我们 mongoexport 命令。在练习时,我遇到了一个典型的问题,包括教练在内的其他同学都没有遇到过。我在我的 Windows 10 机器上使用 Mongo
我是 JSON Schema 的新手,读过什么是 JSON Schema 等等。但我不知道如何将 JSON Schema 链接到 JSON 以针对该 JSON Schema 进行验证。谁能解释一下?
在 xml 中,我可以在另一个 xml 文件中包含一个文件并使用它。如果您的软件从 xml 获取配置文件但没有任何方法来分离配置,如 apache/ngnix(nginx.conf - site-av
我有一个 JSON 对象,其中包含一个本身是 JSON 对象的字符串。我如何反序列化它? 我希望能够做类似的事情: #[derive(Deserialize)] struct B { c: S
考虑以下 JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } 我想定义一个泛型读取 Reads[Outer[T]]对于这种序列化的 Json import
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve
我的旧项目在 MySQL 中有 Standard JSON 格式的数据。 对于我在 JS (Node.js) 和 DynamoDB 中的全新项目,关于 Standard JSON格式: 是否建议将其转
JSON 值字符串、数字、true、false、null 是否是有效的 JSON? 即,是 true 一个有效的 JSON 文档?还是必须是数组/对象? 一些验证器接受这个(例如 http://jso
我有一个 JSON 字符串,其中一个字段是文本字段。这个文本字段可以包含用户在 UI 中输入的文本,如果他们输入的文本是 JSON 文本,也许是为了说明一些编码,我需要对他们的文本进行编码,以便它不会
我正在通过 IBM MQ 调用处理数据,当由 ColdFusion 10 (10,0,11,285437) 序列化时,0 将作为 +0.0 返回,它会导致无效的 JSON并且无法反序列化。 stPol
我正在从三个数组中生成一个散列,然后尝试构建一个 json。我通过 json object has array 成功了。 require 'json' A = [['A1', 'A2', 'A3'],
我从 API 接收 JSON,响应可以是 30 种类型之一。每种类型都有一组唯一的字段,但所有响应都有一个字段 type 说明它是哪种类型。 我的方法是使用serde .我为每种响应类型创建一个结构并
我正在下载一个 JSON 文件,我已将其检查为带有“https://jsonlint.com”的有效 JSON 到文档目录。然后我打开文件并再次检查,结果显示为无效的 JSON。这怎么可能????这是
我正在尝试根据从 API 接收到的数据动态创建一个 JSON 对象。 收到的示例数据:将数据解码到下面给出的 CiItems 结构中 { "class_name": "test", "
我想从字符串转换为对象。 来自 {"key1": "{\n \"key2\": \"value2\",\n \"key3\": {\n \"key4\": \"value4\"\n }\n
目前我正在使用以下代码将嵌套的 json 转换为扁平化的 json: import ( "fmt" "github.com/nytlabs/gojsonexplode" ) func
我有一个使用来自第三方 API 的数据的应用程序。我需要将 json 解码为一个结构,这需要该结构具有“传入”json 字段的 json 标签。传出的 json 字段具有不同的命名约定,因此我需要不同
我想使用 JSON 架构来验证某些值。我有两个对象,称它们为 trackedItems 和 trackedItemGroups。 trackedItemGroups 是组名称和 trackedItem
考虑以下案例类模式, case class Y (a: String, b: String) case class X (dummy: String, b: Y) 字段b是可选的,我的一些数据集没有字
我正在存储 cat ~/path/to/file/blah | 的输出jq tojson 在一个变量中,稍后在带有 JSON 内容的 curl POST 中使用。它运作良好,但它删除了所有换行符。我知
我是一名优秀的程序员,十分优秀!