-3

我从http://appfulcrum.com/2011/09/21/listview-example-5-using-sqlite-database/举了一个例子 ,代码中有一个错误

package com.appfulcrum.blog.examples.listviewcustomdb;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.SQLException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class CustomListViewDB extends ListActivity {

private ListView mainListView = null;
CustomSqlCursorAdapter adapter = null;
private SqlHelper dbHelper = null;
private Cursor currentCursor = null;

private ListView listView = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple);

    if (this.dbHelper == null) {
        this.dbHelper = new SqlHelper(this);

    }

    listView = getListView();
    listView.setItemsCanFocus(false);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    Button btnClear = (Button) findViewById(R.id.btnClear);
    btnClear.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Toast.makeText(getApplicationContext(),
                    " You clicked Clear button", Toast.LENGTH_SHORT).show();
            ClearDBSelections();

        }
    });

    new SelectDataTask().execute();

    this.mainListView = getListView();

    mainListView.setCacheColorHint(0);

}

@Override
protected void onRestart() {
    super.onRestart();
    new SelectDataTask().execute();
}

@Override
protected void onPause() {

    super.onPause();
    this.dbHelper.close();
}

protected void ClearDBSelections() {

    this.adapter.ClearSelections();

}

private class SelectDataTask extends AsyncTask<string, void,="" string=""> {

    protected void onPreExecute() {
        // this.dialog.setMessage("Getting Names...");
        // this.dialog.show();
    }

    protected String doInBackground(final String... args) {

        try {

            CustomListViewDB.this.dbHelper.createDatabase();
            CustomListViewDB.this.dbHelper.openDataBase();

            CustomListViewDB.this.currentCursor = CustomListViewDB.this.dbHelper
                    .getCursor();

        } catch (SQLException sqle) {

            throw sqle;

        }
        return null;
    }

    // can use UI thread here
    protected void onPostExecute(final String result) {

        startManagingCursor(CustomListViewDB.this.currentCursor);
        int[] listFields = new int[] { R.id.txtTitle };
        String[] dbColumns = new String[] { SqlHelper.COLUMN_TITLE };

        CustomListViewDB.this.adapter = new CustomSqlCursorAdapter(
                CustomListViewDB.this, R.layout.single_item,
                CustomListViewDB.this.currentCursor, dbColumns, listFields,
                CustomListViewDB.this.dbHelper);
        setListAdapter(CustomListViewDB.this.adapter);

    }
}

}

行错误

private class SelectDataTask extends AsyncTask<string, void,="" string=""> {

如何写这一行没有错误?并且 Eclipse 仍然对这条线发誓

new SelectDataTask().execute();

写道“CustomListViewDB.SelectDataTask 类型的方法 execute() 未定义”

4

1 回答 1

2

在 Java 中,您不能为变量设置默认值,这不是 C#。

应该:

private class SelectDataTask extends AsyncTask<String, Void, String> {

String - string此外, Java中没有类型的别名。

于 2013-03-25T11:58:39.897 回答