0

こんにちは、私はアンドロイドが初めてで、ツイッターから投稿してステータスを取得するyambaアプリケーションをフォローしています。新しいパーツを追加する前は問題なく動作していました。

別のスレッドを使用して投稿を実行しました。しかし、プロジェクトを実行すると、logcat は「アプリケーションがメイン スレッドで処理しすぎている可能性があります」と表示します。ステータスを入力すると、この doInBackGround メソッドの NullPointException が原因で、「キャッチされていない例外でスレッドが終了しています」と表示されます。

誰でも私を助けることができますか??私はTwitterアカウントを登録して、それがnullでないことを確認しました.でも、答えてくれてありがとう!!

    public class MainActivity extends Activity implements OnClickListener,TextWatcher
    {
    private static final String TAG="StatusActivity";
    EditText editText;
    Button buttonUpdate;
    TextView textCount;
    private YambaApplication yamba;


//constructor
     @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

editText=(EditText) findViewById(R.id.editText);
buttonUpdate=(Button) findViewById(R.id.buttonUpdate);
textCount=(TextView) findViewById(R.id.textCount);
textCount.setText(Integer.toString(140));
textCount.setTextColor(Color.GREEN);

buttonUpdate.setOnClickListener(this);
editText.addTextChangedListener(this);
this.yamba=(YambaApplication)getApplication();
}   


    //Main task of posting, three method of AsyncTask
class PostToTwitter extends AsyncTask<String,Integer,String>
{
    @Override
    protected String doInBackground(String...statuses)
    {
        try{
             Twitter.Status status=yamba.getTwitter().updateStatus(statuses[0]);
             return status.text;
        }
        catch(TwitterException e){
            Log.e(TAG, e.toString());
            e.printStackTrace();
            return "Failed to post";
        }
    }

yamba アプリケーション Java には次のタスクがあります。

    public synchronized Twitter getTwitter(){
    if(twitter==null)
    {
        String username,password,APIroot;
        username=prefs.getString("username", "");
        password=prefs.getString("passord", "");
        APIroot=prefs.getString("APIroot", "http://yamba.marakana.com/api");

     if ( !TextUtils.isEmpty(username) && !TextUtils.isEmpty(password) && !TextUtils.isEmpty(APIroot) )
         {
            twitter= new Twitter(username,password);
             twitter.setAPIRootUrl(APIroot);
          }
     }
    return this.twitter;
  } 
4

1 に答える 1