Hello I am new to android and is following a yamba application which posts and get status from the twitter. I was working fine before I added the new part.
I used a different thread to perform the post. But once I run the project, logcat says"application may be doing too much work on main thread".When I type in status,"thread exiting with uncaught exception",due to NullPointException in this doInBackGround method.
Anyone can help me??I have even registered a Twitter account to make sure it is not null.But Thanks alot for any answer!!
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";
}
}
There is this task in the yamba application 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;
}