2016-04-07 17 views
0
numaralı telefona dönüyor

YouTube Data API'u kullanmaya çalışıyorum. Bir Java istemcisi oluşturdular. Sunucularına bir istek göndermek için izlemeyi denediğim Here is the sample. Android'in ana iş parçacığı üzerinde ağ oluşturmasına izin vermediğinden, ana iş parçacığına buAsyncTask doInBackground()

sahip olamaz. Bu yüzden doInBackground yöntemi içinde

return params[0].execute(); 

çalıştı AsyncTask

public class youtubeSearchTask extends AsyncTask<YouTube.Search.List, Void, SearchListResponse> { 

    @Override 
    protected SearchListResponse doInBackground(YouTube.Search.List... params) { 
     SearchListResponse a; 
     try { 
      a = params[0].execute(); 
     } catch (java.io.IOException ioe) { 
      ioe.printStackTrace(); 
     } 
     return a; 
    } 

    @Override 
    protected void onPostExecute(SearchListResponse searchResponse) { 
     List<SearchResult> searchResultList = searchResponse.getItems(); 
     List<String> videoIds = new ArrayList<String>(); 

     if (searchResultList != null) { 

      // Merge video IDs 
      for (SearchResult searchResult : searchResultList) { 
       videoIds.add(searchResult.getId().getVideoId()); 
      } 
      Joiner stringJoiner = Joiner.on(','); 
      String videoId = stringJoiner.join(videoIds); 

      // Call the YouTube Data API's youtube.videos.list method to 
      // retrieve the resources that represent the specified videos. 
      try { 
       YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet, statistics").setId(videoId); 
       new videoSearchTask().execute(listVideosRequest); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

} 

kullanmaya çalıştı ama bana olası bir IOException hesaba yaptı. Bu yüzden kodu değiştirdim ve şimdi variable 'a' might not have been initialized diyor. Ben ne yaparım?

cevap

0

Eğer değişkeni başlatmak Belki bir en azından boş SearchListResponse a = null; ile bu a not initialized

kaldıracaktır