gpt4 book ai didi

安卓推特应用 : suspended (exception( Twitter Exception))

转载 作者:行者123 更新时间:2023-11-30 04:32:47 25 4
gpt4 key购买 nike

我想创建一个简单的 Twitter 更新应用程序 android。我在 http://marakana.com/forums/android/examples/69.html 找到.这是代码 MyTwitter.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;
}
}

另一个是 Prefs.java :

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:

<?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>

当我点击更新按钮时。它强制关闭,我收到以下错误:

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 有关系吗?谢谢

最佳答案

快速查看,您需要调用 setAuthentication

我查看了堆栈跟踪,用谷歌搜索“URLConnectionHttpClient.post(String, Map, boolean) line: 279”

必须 http://code.google.com/p/andriod-mytwitter/source/browse/JTwitter/src/winterwell/jtwitter/URLConnectionHttpClient.java?spec=svn39&r=39

阅读代码然后得出上述结论是因为你似乎没有调用setAuthentication

你快到了,坚持下去!

关于安卓推特应用 : suspended (exception( Twitter Exception)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7398124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com