I'm a young computer scientist and I'm learning android development.
I tried since this morning to pass value between 2 inputtext
on the same layout.
When the user edit one inputtext
, I would like to paste the new value to one other inputtext
.
This is my code :
private void syncInput() {
((EditText)findViewById(R.id.firstInput)).addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
EditText EditText1 = (EditText)findViewById(R.id.firstInput);
((EditText)findViewById(R.id.SecondInput)).setText(EditTextATK.EditText1().toString());
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});
}
After the launch of my application, when I edit my firstInput I have this error :
06-22 14:08:25.196: E/AndroidRuntime(519): java.lang.NullPointerException
06-22 14:08:25.196: E/AndroidRuntime(519): at com.d3ckard.toolbox.activity.MyActivity$3.afterTextChanged(MyActivity.java:71)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.widget.TextView.sendAfterTextChanged(TextView.java:6145)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:6328)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.sendTextHasChanged(SpannableStringBuilder.java:897)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:353)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28)
06-22 14:08:25.196: E/AndroidRuntime(519): at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:117)
The line number 71 is this one :
((EditText)findViewById(R.id.SecondInput)).setText(EditTextATK.EditText1().toString());