2015-06-22 32 views
-3

我試圖在Eclipse中編寫的Android Studio link中重寫應用程序。有兩個問題,第一個問題是項目中有這一行:錯誤:無法找到符號類AsyncCallWS Android

import com.example.webserviceactivity.R; 

我無法在Android Studio上編寫這一行。 第二個問題是,在這部分代碼:

b = (Button) findViewById(R.id.button1); 
     //Button Click Listener 
     b.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       //Check if Celcius text control is not empty 
       if (et.getText().length() != 0 && et.getText().toString() != "") { 
        //Get the text control value 
        celcius = et.getText().toString(); 
        //Create instance for AsyncCallWS 
        AsyncCallWS task = new AsyncCallWS(); 
        //Call execute 
        task.execute(); 
       //If text control is empty 
       } else { 
        tv.setText("Please enter Celcius"); 
       } 
      } 
     }); 

我有這樣的錯誤:

error: cannot find symbol class AsyncCallWS Android in this part :

AsyncCallWS task = new AsyncCallWS(); 

我該如何解決這些問題呢?謝謝。

+0

什麼是AsyncCallWS?你有進口嗎? – calvinfly

+0

檢查我的答案。接受它,如果它適合你:) –

回答

1

在你發佈的鏈接上,我看到類似下面的類。在使用它之前在你的項目中創建這個類。

private class AsyncCallWS extends AsyncTask<String, Void, Void> { 
     @Override 
     protected Void doInBackground(String... params) { 
      Log.i(TAG, "doInBackground"); 
      getFahrenheit(celcius); 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      Log.i(TAG, "onPostExecute"); 
      tv.setText(fahren + "° F"); 
     } 

     @Override 
     protected void onPreExecute() { 
      Log.i(TAG, "onPreExecute"); 
      tv.setText("Calculating..."); 
     } 

     @Override 
     protected void onProgressUpdate(Void... values) { 
      Log.i(TAG, "onProgressUpdate"); 
     } 

    } 
0

首先,你必須從我們的代碼刪除import語句或烏爾包名稱替換com.example.webserviceactivity

第二個副本AsyncCallWS從給定的鏈接類,並把你的活動類或在你的項目上創建相同的類。

相關問題