无法解析符号'execute'...调用AsyncTask

时间:2018-01-13 13:39:13

标签: java android android-asynctask

我正在尝试对网址发出GET请求,我创建了一个扩展AsyncTask<Void, Void, Void>的类,我尝试调用new MyClass.execute() ...之前我已经完成了这项工作,今天它不起作用。我做错了什么?

这是我的代码:

public class SignUpActivity extends AppCompatActivity {

String TAG = SignUpActivity.class.getSimpleName();
String URL;

ArrayList<String> countries = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);

    new MyClass.execute();
}

private class MyClass extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        //TODO
    }

    @Override
    protected Void doInBackground(Void... params) {
        HttpHandler sh = new HttpHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(URL, "GET");
        //Handling response in jsonStr code 
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        //TODO
    }

}

3 个答案:

答案 0 :(得分:2)

这是语法错误。它应该是

  

new MyClass()。execute();

不是新的MyClass.execute();

答案 1 :(得分:0)

使用它来获取数据使用返回值:

SELECT m.CreditBalance
FROM Member m
WHERE
    m.CreditBalance < 50
    -- There are no transactions for the member in 2018:
    AND NOT EXISTS (
        SELECT 1
        FROM CreditCard cc
            INNER JOIN CreditDebitTrans cdt ON cdt.CardNo = cc.CardNo
        WHERE cc.MemberID = m.MemberID
            AND cdt.TransDateTime >= '2018-01-01'
            AND cdt.TransDateTime < '2019-01-01'
    );

答案 2 :(得分:0)

doInBackground

将上述课程添加到您的主程序包中,并将其作为@Override protected Void doInBackground(String... params) { // TODO Auto-generated method stub JsonHandler json = new JsonHandler(); String jsonStr = json.makeServiceCall(params[0], JsonHandler.GET); // parse your json data here }

执行
Sub WriteFormulasInSheet()

Dim lRow As Long


    lRow = Cells(Rows.Count, 1).End(xlUp).Row

    Sheets("Consolidator").Activate
    Cells.Range(Cells(5, 4), Cells(lRow, 4)).Value = "=IFERROR(VLOOKUP(RC[-3],MAP!$N:$P,2,0),"""")"


End Sub