【发布时间】:2014-01-27 08:42:08
【问题描述】:
我在使用 android 连接到 php 的代码中出现错误。这是代码,错误在加载中
错误在:(loadAllcars extends AsyncTask) 这是我有错误的一些代码
load().execute()?
public class loadAllcars extends AsyncTask<String, String, String> {
carsList = new ArrayList<HashMap<String, String>>();
new loadAllcarsActivity().excute();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id){
// getting values from selected ListItem
String casrtype = ((TextView) view.findViewById(R.id.casrtype)).getText()
.toString();
Intent in = new Intent(getApplicationContext(),
AllcarsActivity.class);
in.putExtra(TAG_TYPE, casrtype);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
} protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
公共类 loadAllcars 扩展 AsyncTask {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AllcarsActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_cars, "GET", params);
// Check your log cat for JSON reponse
Log.d("All cars: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_MODEL);
if (success == 1) {
// products found
// Getting Array of Products
cars = json.getJSONArray(TAG_CARS);
// looping through All Products
for (int i = 0; i <cars.length(); i++) {
JSONObject c =cars.getJSONObject(i);
String id = c.getString(TAG_TYPE);
String name = c.getString(TAG_CARS);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_CARSTYPE, type);
map.put(TAG_CARSMODEL, model);
// adding HashList to ArrayList
carsList.add(map);
}
【问题讨论】:
-
发送完整代码
-
公共类 loadAllcars 扩展 AsyncTask
{ -
发布完整的 loadAllcars
-
我怎样才能把完整的代码发给你? @Ameer
-
在此处更新您的代码。发布 loadAllcars 类
标签: android mysql android-asynctask