Winterwell.jtwitter.TwitterException$Timeout -- 摘自《学习 Android》一书
当我运行第 71 页的代码时,Eclipse 显示了一些错误:
11-17 09:37:47.077: E/StatusActivity(370): Winterwell.jtwitter.TwitterException$超时: http://yamba.marakana.com/api/statuses/update.json
我不知道发生了什么事,提前感谢:)
PS:我已经问过这个问题 此处,但没有响应
任何帮助将不胜感激:)
代码是:
package com.marakana.yamba;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.text.TextWatcher;
import android.text.Editable;
public class StatusActivity extends Activity implements OnClickListener, TextWatcher{
private static final String TAG = "StatusActivity";
EditText editText;
Button updateButton;
Twitter twitter;
TextView textCount;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status);
//Find views
editText = (EditText) findViewById(R.id.editText1);
updateButton = (Button) findViewById(R.id.buttonUpdateStatus);
updateButton.setOnClickListener(this);
textCount = (TextView) findViewById(R.id.textCount);
textCount.setText(Integer.toString(140));
textCount.setTextColor(Color.GREEN);
editText.addTextChangedListener(this);
twitter = new Twitter("SOMENAME", "SOMEPASS");
twitter.setAPIRootUrl("http://yamba.marakana.com/api");
}
// Asynchronously posts to twitter
class PostToTwitter extends AsyncTask<String, Integer, String> {
// Called to initiate the background activity
@Override
protected String doInBackground(String... statuses){
try{
winterwell.jtwitter.Status status = twitter.updateStatus(statuses[0]);
return status.text;
} catch (TwitterException e){
Log.e(TAG, e.toString());
e.printStackTrace();
return "Failed to post";
}
}
// Called when there's a status to be updated
@Override
protected void onProgressUpdate(Integer... values){
super.onProgressUpdate(values);
}
// Called once the background activity has completed
@Override
protected void onPostExecute(String result){
Toast.makeText(StatusActivity.this, result, Toast.LENGTH_LONG).show();
}
}
//TextWatcher methods
public void afterTextChanged(Editable statusText){
int count = 140 - statusText.length();
textCount.setText(Integer.toString(count));
textCount.setTextColor(Color.GREEN);
if (count < 10)
textCount.setTextColor(Color.YELLOW);
if (count < 0)
textCount.setTextColor(Color.RED);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
// Called when button is clicked//
public void onClick(View v){
String status = editText.getText().toString();
new PostToTwitter().execute(status);
//twitter.setStatus(editText.getText().toString());
Log.d(TAG, "onClicked");
}
}
When I run the code from page 71, eclipse showed me some error:
11-17 09:37:47.077: E/StatusActivity(370):
winterwell.jtwitter.TwitterException$Timeout:
http://yamba.marakana.com/api/statuses/update.json
I don't know what's going on,thanks in advance:)
PS: I have asked this question here, but there is no response
Any help will be appreciated:)
The code is:
package com.marakana.yamba;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.text.TextWatcher;
import android.text.Editable;
public class StatusActivity extends Activity implements OnClickListener, TextWatcher{
private static final String TAG = "StatusActivity";
EditText editText;
Button updateButton;
Twitter twitter;
TextView textCount;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status);
//Find views
editText = (EditText) findViewById(R.id.editText1);
updateButton = (Button) findViewById(R.id.buttonUpdateStatus);
updateButton.setOnClickListener(this);
textCount = (TextView) findViewById(R.id.textCount);
textCount.setText(Integer.toString(140));
textCount.setTextColor(Color.GREEN);
editText.addTextChangedListener(this);
twitter = new Twitter("SOMENAME", "SOMEPASS");
twitter.setAPIRootUrl("http://yamba.marakana.com/api");
}
// Asynchronously posts to twitter
class PostToTwitter extends AsyncTask<String, Integer, String> {
// Called to initiate the background activity
@Override
protected String doInBackground(String... statuses){
try{
winterwell.jtwitter.Status status = twitter.updateStatus(statuses[0]);
return status.text;
} catch (TwitterException e){
Log.e(TAG, e.toString());
e.printStackTrace();
return "Failed to post";
}
}
// Called when there's a status to be updated
@Override
protected void onProgressUpdate(Integer... values){
super.onProgressUpdate(values);
}
// Called once the background activity has completed
@Override
protected void onPostExecute(String result){
Toast.makeText(StatusActivity.this, result, Toast.LENGTH_LONG).show();
}
}
//TextWatcher methods
public void afterTextChanged(Editable statusText){
int count = 140 - statusText.length();
textCount.setText(Integer.toString(count));
textCount.setTextColor(Color.GREEN);
if (count < 10)
textCount.setTextColor(Color.YELLOW);
if (count < 0)
textCount.setTextColor(Color.RED);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
// Called when button is clicked//
public void onClick(View v){
String status = editText.getText().toString();
new PostToTwitter().execute(status);
//twitter.setStatus(editText.getText().toString());
Log.d(TAG, "onClicked");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
超时异常意味着远程服务器响应缓慢。它还可能表明您的网络连接存在问题(尽管这通常会产生其他错误)。
如果经常发生,请尝试使用 IHttpClient.setTimeout() 方法增加超时设置。
A Timeout exception means the remote server was slow to respond. It could also indicate a problem with your network connection (though that generally produces other errors).
If it happens regularly, try increasing the timeout settings with the IHttpClient.setTimeout() method.
我遇到了同样的错误,当我更新 jtwitter-yamba.jar 时,它现在可以工作了。
http://marakana.com/s/andevcon_android_for_java_developers,270/index.html
I got the same error, and when I updated the jtwitter-yamba.jar it works now.
http://marakana.com/s/andevcon_android_for_java_developers,270/index.html