gpt4 book ai didi

java - OnPost执行结果为空

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:55 25 4
gpt4 key购买 nike

我正在将一些数据从我的应用程序发送到外部服务器。

public class PostKey extends AsyncTask<String, String, String> {
public AsyncResponse delegate = null;

@Override
protected String doInBackground(String... params) {
postData(params[0]);
return null;
}

@Override
protected void onPostExecute(String result){
Log.d(String.valueOf(result), " Result?");
delegate.processFinish(result); // Returns NullPointerException
}

public void postData(String valueIWantToSend) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://domain.com/post.php");

try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("hoi", "test"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);
String responseStr = EntityUtils.toString(response.getEntity());

Log.d(responseStr, "");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}

public interface AsyncResponse {
void processFinish(String output);
}
}

Log.d(responseStr, "");根据发送的数据返回 true 或 false,并记录它。

delegate.processFinish(result);返回 NullPointerException 还提到 public class PostKey extends AsyncTask<String, String, String>即使所有参数都声明为 Strings .

我也尝试过替换 resultresponseStr但这也不起作用。

最佳答案

您的方法调用出现问题delegate.processFinish(result);委托(delegate)未初始化。因此,您正在调用 null 对象上的方法。

关于java - OnPost执行结果为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31475127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com