execute无法解析为AsyncTask类型

execute无法解析为AsyncTask类型

我正在编写一个需要从数据库中获取一些json的应用程序,我收到了数据,但是现在我试图在 ListView 中显示的信息旁边尝试查看一个图标。

造成麻烦的行是:

mChart.setTag(URL);
new DownloadImagesTask.execute(mChart); <------

主要 Activity :
public class MainActivity extends Activity {

  ListView list;
  TextView icon;
  TextView name;
  TextView developer;
  TextView size;

  Button Btngetdata;

  ArrayList<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();

  private static String url = "http://appwhittle.com/getdata.php";

  private static final String TAG_ITEM = "app_item";
  private static final String TAG_ICON = "app_icon";
  private static final String TAG_NAME = "app_name";
  private static final String TAG_DEVELOPER = "app_developer";
  private static final String TAG_SIZE = "app_size";

  JSONArray mJsonArray = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mList = new ArrayList<HashMap<String, String>>();

        new JSONParse().execute();
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
       private ProgressDialog pDialog;
      @Override
        protected void onPreExecute() {
            super.onPreExecute();

            icon = (TextView)findViewById(R.id.icon);
            name = (TextView)findViewById(R.id.name);
            size = (TextView)findViewById(R.id.size);
            developer = (TextView)findViewById(R.id.developer);

            pDialog = new ProgressDialog(MainActivity.this);
            pDialog.setMessage("Getting Data ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
      }

      @Override
        protected JSONObject doInBackground(String... args) {
        JSONParser jParser = new JSONParser();
        // Getting JSON from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        return json;
      }
       @Override
         protected void onPostExecute(JSONObject json) {
         pDialog.dismiss();
         try {
            mJsonArray = json.getJSONArray(TAG_ITEM);
            for(int i = 0; i < mJsonArray.length(); i++){
            JSONObject c = mJsonArray.getJSONObject(i);

            String name = c.getString(TAG_NAME);
            String size = c.getString(TAG_SIZE);
            String developer = c.getString(TAG_DEVELOPER);
            String icon = c.getString(TAG_ICON);

            HashMap<String, String> map = new HashMap<String, String>();
            map.put(TAG_ICON, icon);
            map.put(TAG_NAME, name);
            map.put(TAG_DEVELOPER, "Developer: " + developer);
            map.put(TAG_SIZE, size + " MB");


            mList.add(map);
            list=(ListView)findViewById(R.id.list);

            ListAdapter adapter = new SimpleAdapter(MainActivity.this, mList,
                R.layout.list_v,
                new String[] {TAG_NAME, TAG_DEVELOPER, TAG_SIZE }, new int[] {
                    R.id.name, R.id.developer, R.id.size});

            ImageView mChart = (ImageView) findViewById(R.id.icon);
            String URL = "http://www...anything ...";

            mChart.setTag(URL);
            new DownloadImagesTask.execute(mChart);

            list.setAdapter(adapter);
            list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        Toast.makeText(MainActivity.this, "You Clicked at "+ mList.get(+position).get(TAG_NAME), Toast.LENGTH_SHORT).show();
                    }
                });
            }
        } catch (JSONException e) {
          e.printStackTrace();
        }
       }
    }
}

DownloadImagesTask:
public class DownloadImagesTask extends AsyncTask<ImageView, Void, Bitmap> {

    ImageView imageView = null;

    @Override
    protected Bitmap doInBackground(ImageView... imageViews) {
        this.imageView = imageViews[0];
        return download_Image((String)imageView.getTag());
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }


    private Bitmap download_Image(String url) {
        return null;
        }
    }

任何帮助深表感谢!提前致谢!

最佳答案

代替

new DownloadImagesTask.execute(mChart);


new DownloadImagesTask().execute(mChart);

试试这个。会工作的。

关于java - .execute无法解析为AsyncTask类型(Android),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24117724/

10-12 02:44