Wednesday 15 May 2013

android.widget.Button cannot be cast to android.widget.EditText -


Text after "div" = "itemprop =" text ">

Developing my first Android calculator application, I succeeded in updating a TextView in a new activity by passing the answer by a purpose But for this, the user needs to hit back to make another calculation. I'm trying to create a simple textView update in the DoCalculation Button MainActivity and the error is happening:

06-22 November: 08: 17.318: E / AndroidRuntime (31328): java.lang: of Because of .classCastException: android.widget.Button android.widget.EditText can not be molded

Here is my code:

  / ** is called user Calculates when calculates! Button * / Public Zero (see View) {// Do something in response to the button int reply; String reply; EditTake numberOn = (Edit Text) FindBUIID (RID No. 1); Edit Text Number = (Edit Text) Find VVBID (RID No. 2); Int noonai = integer.precent (number ongatetext). ToString ()); Int ntro = integer.precent (number two.gate text). ToString ()); AnswerInt = numberOnee * number two; Answer = integer Tosting (NorthInt); TextView HomeInvoicesview = (TextView) Find VVBID (R.D.HHMANAnAviewView); HomeAnswerView.setTextSize (40); HomeAnswerView.setText (Answer); }   

For reference, here is the code that is successfully starting a new activity:

  // The user has calculated when the call is made ! Button Public Zero doCalculation (see footage) {// Do something in response to the button int answer; String reply; Intent = intent (newer than this, DisplayCalculationActivity.class); EditTake numberOn = (Edit Text) FindBUIID (RID No. 1); Edit Text Number = (Edit Text) Find VVBID (RID No. 2); Int noonai = integer.precent (number ongatetext). ToString ()); Int ntro = integer.precent (number two.gate text). ToString ()); AnswerInt = numberOnee * number two; Answer = integer Tosting (NorthInt); Intent.putExtra (EXTRA_MESSAGE, answer); StartActivity; }   

XML for update,

  & lt; Android: layout_centerHorizontal = "true" Android: layout_marginTop = "Android: layout_height =" wrap_content "android: layout_below =" @ + id / textView3 "Android: layout_centerHorizontal =" true "Android: layout = 16dp "Android: EMS =" 10 "Android: inputType =" number "/> & Lt; Android: layout_center = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ + id / textView1" Android: layout_centerHorizontal = "true" Android: EMS = "Edit" 10 "Android: inputType =" number "Android: singleLine =" true "/> & Lt; Android: layout_alignLeft = "@ + id / number 2" Android: layout_alignRight = "@ + id / number 2" android: id = "@ + id / calculateBtn" Android: layout_width = "wrap_content" android: layout_height = "wrap_content" Android: Layout_bale = "@ + ID / Number 2" Android: layout_margintop = "14dp" Android: onClick = "doCalculation" Android: text = "count!" / & Gt;   

Thanks for your help, -Michael

As if R.id.number1 or R.id.number2 is a button to check your XML and make sure it is an EditText.

EDIT: The original answer was not working, but the project cleansed the problem cleanly.

No comments:

Post a Comment