Android的AsyncTask的PARAMS未找到 [英] Android AsyncTask params not found

查看:159
本文介绍了Android的AsyncTask的PARAMS未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android / Java,但我公司拥有先进的C#和.NET的知识。

i am new to android / java but i have advanced knowledge in c# and .Net.

我与AsyncTask的一个问题。

I have a problem with the AsyncTask.

我的code:

import android.os.AsyncTask;

public class testtask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String response = ""; // BREAKPOINT HERE

        return "";
    }

    @Override
    protected void onPostExecute(String result) {
    }
}

和呼叫:

public void RequestDepartments(View view) {
    BamakiWebService service = new BamakiWebService();
            RequestType request = new RequestType();

            request.Uri = "departments/all";


            try {

                testtask task = new testtask();
                task.execute("wfwef");

            }
            catch (Exception ex) {
                Log.e("Main", ex.getMessage());
            }
}

在code,因为我无法访问的网址失败?
当我调试doInBackground并添加网址,看它说无法找到本地变量的URL'? (上断点 - > //断点的位置)

The Code fails because i can not access the urls?! When i debug the doInBackground and add the urls to watch it says "Cannot find local variable 'urls'"?! ( on BreakPoint -> // BREAKPOINT HERE)

我在做什么错?!

修改

改变执行以

testtask task = new testtask();
String[] params = new String[] {"wfwef"};
task.execute(params);

没解决的问题...

Did not solved the Problem ...

推荐答案

您不需要传递一个字符串数组!如果你只是路过一根弦,你可以访问 doInBackground 该字符串使用URL [0]!希望它能帮助

You don't need to pass a string-array! If you are passing just one string you can access that string in doInBackground with urls[0]! Hope it helps

yourAsyncTask.execute(Your URL String);

而在 doInBackground 访问URL像你使用数组做。网址[0]

And in doInBackground access urls as like you would do with an array. urls[0]

这篇关于Android的AsyncTask的PARAMS未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆