Android 对象的makeHttpRequest未定义
大家好,这是我的代码,我在方法makeHttpRequest(String,String,List)中遇到了这个错误 未为类型JSONParser定义 如何处理这个问题请有人帮帮我 为什么JSONParser没有定义makeHttpRequestAndroid 对象的makeHttpRequest未定义,android,Android,大家好,这是我的代码,我在方法makeHttpRequest(String,String,List)中遇到了这个错误 未为类型JSONParser定义 如何处理这个问题请有人帮帮我 为什么JSONParser没有定义makeHttpRequest protected String doInBackground(String... args) { // Building Parameters List<NameValuePair> params = ne
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
NewProductActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
受保护的字符串doInBackground(字符串…args){
//建筑参数
List params=new ArrayList();
//从URL获取JSON字符串
JSONObject json=jParser.makeHttpRequest(url_all_products,“GET”,params);
//检查日志cat中的JSON响应
Log.d(“所有产品:,json.toString());
试一试{
//检查成功标签
int success=json.getInt(TAG_success);
如果(成功==1){
//发现的产品
//获取一系列产品
products=json.getJSONArray(TAG_products);
//在所有产品中循环
对于(int i=0;ivalue
地图放置(标签PID,id);
地图放置(标签名称、名称);
//将哈希列表添加到ArrayList
productsList.add(地图);
}
}否则{
//没有发现任何产品
//启动添加新产品活动
意图i=新意图(getApplicationContext(),
NewProductActivity.class);
//关闭以前的所有活动
i、 添加标志(意图、标志、活动、清除、顶部);
星触觉(i);
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
使用以下代码:
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
DefaultHttpClient defaultClient = new DefaultHttpClient();
// Setup the get request
HttpGet httpGetRequest = new HttpGet("http://10.0.2.2:8080");
try{
// Execute the request in the client
HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
// Grab the response
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
json = reader.readLine();
}catch(Exception e){
Log.d("Error",e.toString());
}
你能发布一些相关的代码吗?我不是在大约1小时前看到过同样的问题吗?你在使用什么API?谁是jsonParser?看这是我的密码