Java 异步任务错误

Java 异步任务错误,java,android,eclipse,android-asynctask,Java,Android,Eclipse,Android Asynctask,我试图为方法实现asynctask,但遇到错误。我不知道是什么问题,也不知道我哪里做错了 下面是我的代码 class abc extends AsyncTask<String, String, String> { protected String doInBackground(String... message) { Bundle parameters = new Bundle(); parameters.putString("message"

我试图为方法实现asynctask,但遇到错误。我不知道是什么问题,也不知道我哪里做错了

下面是我的代码

class abc extends AsyncTask<String, String, String> {
    protected String doInBackground(String... message) {
        Bundle parameters = new Bundle();
        parameters.putString("message", message);
        parameters.putString("description", "topic share");
        try {
            facebook.request("me");
            String response = facebook.request("me/feed", parameters, "POST");
            Log.d("Tests", "got response: " + response);
            if (response == null || response.equals("")
                    || response.equals("false")) {
                showToast("Blank response.");
            } else {
                showToast("Message posted to your facebook wall!");
            }
            finish();
        } catch (Exception e) {
            showToast("Failed to post to wall!");
            e.printStackTrace();
            finish();
        }
        return null;
    }
}

错误说明:类型绑定中的方法putString(String,String)不适用于参数(String,String[])

错误说明您试图使用错误的参数类型调用方法。该方法需要一个
字符串
作为第二个参数,但您使用的是
String[]
(字符串数组)

在这种情况下,此错误的解决方案相当简单,因为Android API为
String[]
提供了一种方法。替换

parameters.putString("message", message);


因为您只需要第一个元素,所以请使用此代码。它检查数组的长度以避免出现
ArrayOutOfBoundsException

if (message.length > 0) {
    parameters.putString("message", message[0]);
}

该错误指出,您试图使用错误的参数类型调用方法。该方法需要一个
字符串
作为第二个参数,但您使用的是
String[]
(字符串数组)

在这种情况下,此错误的解决方案相当简单,因为Android API为
String[]
提供了一种方法。替换

parameters.putString("message", message);


因为您只需要第一个元素,所以请使用此代码。它检查数组的长度以避免出现
ArrayOutOfBoundsException

if (message.length > 0) {
    parameters.putString("message", message[0]);
}
问题在于这个

字符串。。。是一种数据类型,它接受一组字符串。所以你不能把它转换成字符串

我理解你的问题,最简单的解决方法是

改变

parameters.putString("message", message);

因此,这将获取传递给asynctask的第一个字符串

如果您有任何问题,请告诉我。

问题在于此

字符串。。。是一种数据类型,它接受一组字符串。所以你不能把它转换成字符串

我理解你的问题,最简单的解决方法是

改变

parameters.putString("message", message);

因此,这将获取传递给asynctask的第一个字符串


如果您有任何问题,请告诉我。

请勿在doInBackground中执行ui操作。在OnPostExecute()和onPreexecute()中执行。不要在doInBackground中执行ui操作。在OnPostExecute()和onPreexecute()中执行此操作。我是否可以将字符串[]改为字符串?@Justin:由于
message
是一个数组,您只需使用
参数选择第一个元素即可。putString(“message”,message[0])。但是您需要检查长度,因为
消息
可能为空。我将其更改为消息[0],但显示索引超出范围时出错exception@Justin:更新了我的答案。但是如果你得到这个,你应该检查你的程序逻辑,因为你希望
message
至少有一个元素。我可以把字符串[]改为String吗?@Justin:message
是一个数组,你可以用
参数选择第一个元素。putString(“message”,message[0])。但是您需要检查长度,因为
消息
可能为空。我将其更改为消息[0],但显示索引超出范围时出错exception@Justin:更新了我的答案。但是如果您得到了这个结果,您应该检查您的程序逻辑,因为您希望
message
至少有一个元素。错误表示数组索引越界异常错误您必须将消息字符串作为参数传递给
execute()
。那么为什么要使用message参数呢。为什么不将其设置为Voiderror,即数组索引越界异常错误您必须将消息字符串作为参数传递给
execute()
。那么为什么您有一个消息参数呢。你为什么不把它作废呢