我还是 Android 编程的新手。我正在学习一本名为 Learning Android 的书中的教程。当我单击更新按钮时,我最终崩溃了。知道为什么吗?堆栈跟踪如下。我得到一个致命的例外:主要
package com.marakana.yamba;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class StatusActivity extends Activity implements OnClickListener{
private static final String TAG ="StatusActivity";
Twitter twitter;
EditText editText;
Button updateButton ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status);
// Find Views
editText = (EditText) findViewById(R.id.editText);
updateButton = (Button) findViewById(R.id.updateButton);
updateButton.setOnClickListener(this);
twitter = new Twitter("Yamba18", "undertaker");
twitter.setAPIRootUrl("http://yamba.marakana.com/api");
}
//Asynchronously Post to Twitter
class PostToTwitter extends AsyncTask<String, Integer, String>{
@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 "Failedd to Post";
}
}
@Override
protected void onProgressUpdate (Integer... values){
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result){
Toast.makeText(StatusActivity.this, result, Toast.LENGTH_LONG).show();
}
}
public void onClick(View v){
twitter.setStatus(editText.getText().toString());
Log.d(TAG, "onClicked");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.status, menu);
return true;
}
}
这是日志猫。
09-26 17:25:56.469: D/AndroidRuntime(612): Shutting down VM
09-26 17:25:56.469: W/dalvikvm(612): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
09-26 17:25:56.529: E/AndroidRuntime(612): FATAL EXCEPTION: main
09-26 17:25:56.529: E/AndroidRuntime(612): winterwell.jtwitter.TwitterException: java.io.IOException: Received authentication challenge is null
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:533)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.URLConnectionHttpClient.post2_connect(URLConnectionHttpClient.java:413)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.URLConnectionHttpClient.post2(URLConnectionHttpClient.java:379)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:348)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2762)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2694)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.Twitter.setStatus(Twitter.java:2482)
09-26 17:25:56.529: E/AndroidRuntime(612): at com.marakana.yamba.StatusActivity.onClick(StatusActivity.java:68)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.view.View.performClick(View.java:3480)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.view.View$PerformClick.run(View.java:13983)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.os.Handler.handleCallback(Handler.java:605)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.os.Handler.dispatchMessage(Handler.java:92)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.os.Looper.loop(Looper.java:137)
09-26 17:25:56.529: E/AndroidRuntime(612): at android.app.ActivityThread.main(ActivityThread.java:4340)
09-26 17:25:56.529: E/AndroidRuntime(612): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 17:25:56.529: E/AndroidRuntime(612): at java.lang.reflect.Method.invoke(Method.java:511)
09-26 17:25:56.529: E/AndroidRuntime(612): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-26 17:25:56.529: E/AndroidRuntime(612): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-26 17:25:56.529: E/AndroidRuntime(612): at dalvik.system.NativeStart.main(Native Method)
09-26 17:25:56.529: E/AndroidRuntime(612): Caused by: java.io.IOException: Received authentication challenge is null
09-26 17:25:56.529: E/AndroidRuntime(612): at libcore.net.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:397)
09-26 17:25:56.529: E/AndroidRuntime(612): at libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:345)
09-26 17:25:56.529: E/AndroidRuntime(612): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:276)
09-26 17:25:56.529: E/AndroidRuntime(612): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
09-26 17:25:56.529: E/AndroidRuntime(612): at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:468)
09-26 17:25:56.529: E/AndroidRuntime(612): ... 18 more
09-26 17:25:59.169: I/Process(612): Sending signal. PID: 612 SIG: 9