2016-04-30 2 views
-1

ここに私のアプリケーションにGoogleシートから情報をダウンロードするための私のコードです。 my android studio cantがこのクラスを見つけたようです。 この問題について私は何ができますか?道に迷いました。ありがとう。 は、私はこのチュートリアルからこのコードを取った:あなたは輸入にAsyncResultのためのクラスが含まれていないため http://www.telerik.com/blogs/google-spreadsheet-as-data-source-androidは、 'AsyncResult'シンボルを解決できません

package yrapps.szone; 
 
import android.os.AsyncTask; 
 

 
import org.json.JSONException; 
 
import org.json.JSONObject; 
 

 
import java.io.BufferedReader; 
 
import java.io.IOException; 
 
import java.io.InputStream; 
 
import java.io.InputStreamReader; 
 
import java.net.HttpURLConnection; 
 
import java.net.URL; 
 

 
public class DownloadWebpageTask extends AsyncTask<String, Void, String> { 
 
    AsyncResult callback; 
 

 
    public DownloadWebpageTask(AsyncResult callback) { 
 
     this.callback = callback; 
 
    } 
 

 
    @Override 
 
    protected String doInBackground(String... urls) { 
 

 
     // params comes from the execute() call: params[0] is the url. 
 
     try { 
 
      return downloadUrl(urls[0]); 
 
     } catch (IOException e) { 
 
      return "Unable to download the requested page."; 
 
     } 
 
    } 
 

 
    // onPostExecute displays the results of the AsyncTask. 
 
    @Override 
 
    protected void onPostExecute(String result) { 
 
     // remove the unnecessary parts from the response and construct a JSON 
 
     int start = result.indexOf("{", result.indexOf("{") + 1); 
 
     int end = result.lastIndexOf("}"); 
 
     String jsonResponse = result.substring(start, end); 
 
     try { 
 
      JSONObject table = new JSONObject(jsonResponse); 
 
      callback.onResult(table); 
 
     } catch (JSONException e) { 
 
      e.printStackTrace(); 
 
     } 
 
    } 
 

 
    private String downloadUrl(String urlString) throws IOException { 
 
     InputStream is = null; 
 

 
     try { 
 
      URL url = new URL(urlString); 
 
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
 
      conn.setReadTimeout(10000 /* milliseconds */); 
 
      conn.setConnectTimeout(15000 /* milliseconds */); 
 
      conn.setRequestMethod("GET"); 
 
      conn.setDoInput(true); 
 
      // Starts the query 
 
      conn.connect(); 
 
      int responseCode = conn.getResponseCode(); 
 
      is = conn.getInputStream(); 
 

 
      String contentAsString = convertStreamToString(is); 
 
      return contentAsString; 
 
     } finally { 
 
      if (is != null) { 
 
       is.close(); 
 
      } 
 
     } 
 
    } 
 

 
    private String convertStreamToString(InputStream is) { 
 
     BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
 
     StringBuilder sb = new StringBuilder(); 
 

 
     String line = null; 
 
     try { 
 
      while ((line = reader.readLine()) != null) { 
 
       sb.append(line + "\n"); 
 
      } 
 
     } catch (IOException e) { 
 
      e.printStackTrace(); 
 
     } finally { 
 
      try { 
 
       is.close(); 
 
      } catch (IOException e) { 
 
       e.printStackTrace(); 
 
      } 
 
     } 
 
     return sb.toString(); 
 
    } 
 
}

+0

あなたはいつも代わりに –

答えて

1

あなたはシンボルを解決できません。 AsyncResultは標準のAndroidコードではありません。あなたのリンクに記載されているGitHubリポジトリに行くと、それはDownloadWebpageTaskと同じパッケージの一部であるカスタムクラスであることがわかります。それが彼がそれを無料で入手する理由です。しかし、AsyncResultを自分で作成する必要があります。ここで

が彼の源である:https://github.com/telerik/Android-samples/blob/master/Blogs/Json-Reader/app/src/main/java/com/example/progress/json_reader/AsyncResult.java

+0

を簡単なハンドラを使用することができますありがとうありがとうありがとう。 –

関連する問題