Reputation: 18130
I have a simple messaging application that gets the text of an editText box and sends it to the server. All I want to do is when the text gets sent to the server, I want the editText box to reset.
Here is my code that works but, it doesn't reset the editText box:
public void sendMessage(View v) {
Editable messagetext;
messagetext = message.getText();
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
username = prefs.getString("username", "null");
where = prefs.getString("chat", "null");
message = (EditText) findViewById(R.id.inptbox);
function = new Functions();
response = function
.sendMessage(username, where, messagetext.toString());
}
If I add one more line of code, in order to reset the box my application dies:
public void sendMessage(View v) {
Editable messagetext;
messagetext = message.getText();
message.setText("");
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
username = prefs.getString("username", "null");
where = prefs.getString("chat", "null");
message = (EditText) findViewById(R.id.inptbox);
function = new Functions();
response = function
.sendMessage(username, where, messagetext.toString());
}
The error I get (bear with me, I'm not that good logcat) is:
E/AndroidRuntime(7207): java.lang.IllegalStateException: Could not execute method of the activity
List of global variables:
String username = "";
Functions function;
EditText message;
String response = "";
String where = "";
String inboxx;
Upvotes: 0
Views: 307
Reputation: 35943
...
messagetext = message.getText();
...
message = (EditText) findViewById(R.id.inptbox);
...
Should not the order of these be reversed? You should need to say what 'message' is before you call getText
on it.
Upvotes: 2