2015-07-19 26 views
-1
class EndpointsAsyncTask extends AsyncTask<Integer, Void, MyBean> { 

private static MyApi myApiService = null; 
public EndpointsAsyncTask(){ 
    MyApi.Builder builder=new MyApi.Builder(AndroidHttp.newCompatibleTransport(),new AndroidJsonFactory(),null); 
    myApiService=builder.build(); 
} 
@Override 
protected MyBean doInBackground(Integer... params) 
{ 
    int no1=params[0]; 

    try { 
     return myApiService.addition(no1).execute(); 
     // return myApiService.addition(name).execute().getNo1(); 
    } catch (IOException e){ 
     Log.e("EndpointsAsyncTask",e.getMessage()); 
     return null; 
    } 
} 

@Override 
protected void onPostExecute(MyBean myBean) { 

    Toast.makeText(this,myBean.getNo1(),Toast.LENGTH_LONG).show(); 
} 

我創建了一個名爲MyBean的類,它有一個方法setter和setNo1和getNo1的getter。 我想顯示在吐司getNo1但我越來越錯誤無法解析方法maketext(com.example.sampleapp.EndpointAsynctask,java.lang.Integer,int)無法解析端點

+1

敬酒要求的上下文。你的asynctask不是一個上下文。 – njzk2

回答

0

你的靈活性的名稱是什麼? 考慮到你的活動名稱爲MyActivity

變化

Toast.makeText(this,myBean.getNo1(),Toast.LENGTH_LONG).show(); 

Toast.makeText(MyActivity.this,myBean.getNo1(),Toast.LENGTH_LONG).show();