2016-05-05 8 views
1

コード内の "execute"という単語が、シンボルメソッドexecute(String)を見つけることができないというエラーを引き起こしています。誰もエラーplsを解決するのを助けることができますか?おかげシンボルメソッドが見つかりません。execute(String)-Android Studio

public void onClickGetWeather(View v) { 

    EditText editText = (EditText) findViewById(R.id.editTextCountry); 
    String location = editText.getText().toString(); 

    weather_fragment task = new weather_fragment(); 
    try { 
     double temp = task.execute(location).get(); 

     TextView tv = (TextView) findViewById(R.id.textView); 
     tv.setText("Temperature: " + temp); 


    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } catch (ExecutionException e) { 
     e.printStackTrace(); 
    } 

} 

weather_fragmentコード:

public class WeatherAsyncTask extends AsyncTask<String, Void, Double> { 

    @Override 
    protected Double doInBackground(String... params) { 

     String data = ((new WeatherHttpClient()).getWeatherData(params[0])); 

     double temp = 0.0f; 

     try { 
      temp = JSONWeatherParser.getWeather(data); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     return temp; 

    } 
} 
+0

は何ですか:だからあなたは本当にあなたがこのようなものが必要になりますweather_fragmentのインスタンスを通して、あなたのasynctaskを開始したい場合は

WeatherAsyncTask task = new WeatherAsyncTask(); task.execute(string); 

weather_fragment? –

+0

weather_fragmentクラスでexecute(String)というメソッドがありますか? –

+0

@AdnanIsajbegovic weather_fragmentは、非同期タスクを実行するクラスです。これはフラグメントです – user3569503

答えて

0

あなたはすでにこのように呼ばれるメソッドを持っている場合String引数、 を取る方法が必要であるあなたのクラスweather_fragment、その後、overload it(すなわち書き込み同じ名前だが、パラメータとして文字列を持つ別のもの)。b utが1つしか定義されていない場合

0

種類weather_fragmentのオブジェクトのexecute(string)を、AsyncTaskタイプがWeatherAsyncTaskでない場所に呼び出しています。

あなたがこの方法あなたの非同期タスクを呼び出す必要があり

public class weather_fragment ... { 

    public Double execute(String s){ 
     new WeatherAsyncTask().execute(string); 
     // You must get the Double to return from the 
     // onPostExecute(Double d) of the WeatherAsyncTask 
     ... 
    } 

    public class WeatherAsyncTask extends AsyncTask<String, Void, Double> { 
     //... 
    } 
} 
関連する問題