2014-02-19 201 views
0

我正在學習在Android中開發服務並遵循Marakana Yamba示例。winterwell.jtwitter.TwitterException:org.json.JSONException:值java.lang.String類型的<!DOCTYPE無法轉換爲JSONArray

我已經創建了UpdaterService,它可以提取推文和常規時間間隔,以及一個RefreshService,它將在選擇時拉動推文。

對於拉動鳴叫的代碼是在這兩種服務,但在RefreshService我得到以下錯誤,而UpdateService運行withput任何錯誤相同:

02-19 14:31:41.359 1323-1345/com.tutorial.yamba.yamba W/System.err﹕ winterwell.jtwitter.TwitterException: org.json.JSONException: Value (JSONArray.java:96) 02-19 14:31:41.379 1323-1345/com.tutorial.yamba.yamba W/System.err﹕ at org.json.JSONArray.(JSONArray.java:108) 02-19 14:31:41.389 1323-1345/com.tutorial.yamba.yamba W/System.err﹕ at winterwell.jtwitter.Twitter$Status.getStatuses(Twitter.java:339) 02-19 14:31:41.389 1323-1345/com.tutorial.yamba.yamba W/System.err﹕ ... 7 more

下面是RefreshService類

package com.tutorial.yamba.yamba; 

import android.app.IntentService; 
import android.content.Intent; 
import android.util.Log; 

import java.util.List; 

import winterwell.jtwitter.Twitter; 
import winterwell.jtwitter.Twitter.Status; 
import winterwell.jtwitter.TwitterException; 

public class RefreshService extends IntentService { 

    static final String TAG = "RefreshService"; 
    Twitter twitter; 

    public RefreshService() { 
     super(TAG); 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     twitter = new Twitter(someusername, somepassword); 
     twitter.setAPIRootUrl("http://www.yamba.marakana.com/api"); 
     Log.d(TAG, "onCreate"); 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) { 
     Log.d(TAG,"onhandleIntent enter"); 
     try { 
      List<Status> timeline = twitter.getPublicTimeline(); 
      Log.d(TAG,timeline.size()+""); 
      for (Status status : timeline) 
      { 
       Log.d(TAG, String.format("%s: %s", status.user.name, status.text)); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     Log.d(TAG, "onDestroy"); 
    } 


} 

任何幫助將不勝感激。

謝謝。

回答

0

該錯誤消息看起來像服務器返回一個HTML錯誤頁面。 我認爲Marakana服務器可能已經移動(或關閉)。

爲什麼不嘗試直接使用Twitter? 您需要使用oauth進行身份驗證,否則Marakana教程應該沒問題。

或者有identi.ca,它可以使用名稱/密碼。但oauth並不那麼難,而Twitter則更有趣。

注意:最好從http://www.winterwell.com/software/jtwitter.php

+0

下載最新JTwitter但是代碼相同的路徑從UpdateService類工作。 – user3275095

+0

@ user3275​​095 UpdateService類? Jtwitter沒有一個。這是你自己的課程/來自教程的東西嗎?請提供更多細節。 –

+0

準確。這兩個類都來自教程。 – user3275095

相關問題