2011-09-13 13 views
1

私は単純なTwitterアプリのAndroidアプリを作成したいと思っていました。私はhttp://marakana.com/forums/android/examples/69.htmlで見つけました。android twitter app:suspended(例外(Twitter例外))

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background"> 
    <TextView android:text="@string/labelWhatsHappening" android:layout_height="wrap_content" android:textStyle="bold" android:layout_width="fill_parent" android:textSize="30sp" android:gravity="center"></TextView> 
    <EditText 
     android:id="@+id/textStatus" 
     android:typeface="serif" 
     android:textColorHint="#E6E6E6" 
     android:textColor="#E6E6E6" 
     android:maxLength="160" 
     android:hint="@string/hintStatus" 
     android:background="@color/transparentBlue" 
     android:layout_width="fill_parent" 
     android:layout_height="100px" 
     android:layout_margin="5px" 
     android:padding="5px" 
     android:minLines="4"></EditText> 
    <Button 
     android:layout_height="wrap_content" 
     android:id="@+id/buttonUpdate" 
     android:text="@string/labelUpdate" 
     android:layout_width="fill_parent" 
     android:background="@drawable/buttonbg"></Button> 

</LinearLayout> 

私がクリックしてください:ここ

import android.os.Bundle; 
import android.preference.PreferenceActivity; 

public class Prefs extends PreferenceActivity{ 

    @Override 
    public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 

    addPreferencesFromResource(R.xml.prefs); 
    } 

} 

がメインのレイアウトxmlです:Prefs.java

import android.app.Activity; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.preference.PreferenceManager; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
import winterwell.jtwitter.Twitter; 

public class MyTwitter extends Activity implements OnClickListener 
{ 

    static final String TAG = "MyTwitter"; 

    Twitter twitter; 
    SharedPreferences prefs; 

    Button buttonUpdate; 
    Button buttonPrefs; 
    EditText textStatus; 



    @Override 
    public void onClick(View src) 
    { 

     String status = textStatus.getText().toString(); 

     Log.d(TAG, "Clicked on "+ status); 

     // Toast 
     Toast.makeText(this, textStatus.getText(), Toast.LENGTH_LONG).show(); 

     // set twitter status 
     twitter.setStatus(status); 

     //reset status string 
     textStatus.setText(""); 
    } 
    /** Called when the activity is first created. */ 
    @SuppressWarnings("deprecation") 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // find views by id 
     buttonUpdate = (Button) findViewById(R.id.buttonUpdate); 
     textStatus = (EditText) findViewById(R.id.textStatus); 

     // Add listener 
     buttonUpdate.setOnClickListener(this); 

     //Initialize twitter 
     prefs = PreferenceManager.getDefaultSharedPreferences(this); 
     String username = prefs.getString("username", "n/a"); 
     String password = prefs.getString("password", "n/a"); 
     if (username != null && password != null){ 
      twitter = new Twitter(username, password); 
     } 


    } 

    @Override 
    // when the menu button is pressed another layout is shown. that is menu 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.menu, menu); 
     return true; 
    } 

    // Called when menu item is selected // 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 

     switch(item.getItemId()){ 

     case R.id.menuPrefs: 
     // Launch Prefs activity 
     Intent i = new Intent(MyTwitter.this, Prefs.class); 
     startActivity(i); 
     Log.d(TAG, "MenuPrefs starting Prefs"); 
     Toast.makeText(MyTwitter.this, textStatus.getText(), Toast.LENGTH_LONG).show(); 
     break; 

     }  
     return true; 
    } 
} 

およびその他のいずれかになります。ここで は、コードMyTwitter.Javaです更新ボタン。強制終了すると、次のエラーが表示されます。

Thread [<1> main] (Suspended (exception TwitterException)) 
    URLConnectionHttpClient.post(String, Map, boolean) line: 279  
    Twitter.updateStatus(String, Number) line: 2471 
    Twitter.updateStatus(String) line: 2411 
    Twitter.setStatus(String) line: 2183  
    MyTwitter.onClick(View) line: 45  
    Button(View).performClick() line: 2485 
    View$PerformClick.run() line: 9080 
    ViewRoot(Handler).handleCallback(Message) line: 587 
    ViewRoot(Handler).dispatchMessage(Message) line: 92 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 3683  
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
    Method.invoke(Object, Object...) line: 507 
    ZygoteInit$MethodAndArgsCaller.run() line: 839 
    ZygoteInit.main(String[]) line: 597 
    NativeStart.main(String[]) line: not available [native method] 

TwitterExceptionと関係がありますか?ありがとう

答えて

1

非常にクイックレビュー、setAuthenticationを呼び出す必要があります。その後、コードを読む http://code.google.com/p/andriod-mytwitter/source/browse/JTwitter/src/winterwell/jtwitter/URLConnectionHttpClient.java?spec=svn39&r=39

ガット基づいて上記の結論に達しました:

私は、Googleで「279 URLConnectionHttpClient.post(文字列、地図、ブール値)のラインを」スタックトレースを見直しsetAuthenticationを呼び出していないようです。

あなたはほぼそこにいます。