class EndpointsAsyncTask extends AsyncTask<Pair<Context, Integer>, Void, Integer> {
private static MyApi myApiService = null;
private Context context;
@Override
protected Integer doInBackground(Pair<Context, Integer>... params) {
if(myApiService == null) { // Only do this once
MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
.setRootUrl("http://10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}});
myApiService = builder.build();}
context = params[0].first;
int name = params[0].second;
try {
return myApiService.addition(name).execute().getNo1();
// return myApiService.addition(name).execute().getNo1();
} catch (IOException e){
return e.getMessage();
}
}
@Override
protected void onPostExecute(Integer result) {
Toast.makeText(context, result, Toast.LENGTH_LONG).show();
}
}
我想从Android端点发送一个免费的谷歌应用引擎。并希望在谷歌应用引擎页面上显示一个数字。但作为回报e.getMessage();我发现错误不兼容的类型
答案 0 :(得分:0)
protected void onPostExecute(Integer result) { Toast.makeText(context, result, Toast.LENGTH_LONG).show(); }
(如果“结果”不是资源ID)
Toast.makeText()将String作为第二个参数。
尝试
Toast.makeText(context, "" + result, Toast.LENGTH_LONG).show();