java code of my calculator app made in android studio. It got crashed -


    package com.example.android.mycalculator;      import android.os.bundle;     import android.support.v7.app.actionbaractivity;     import android.view.view;     import android.widget.edittext;     import android.widget.textview;       public class mainactivity extends actionbaractivity {         int qty = 0;         @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);   string val = ((edittext)findviewbyid(r.id.input1)).gettext().tostring();         int num1 = integer.valueof(val);         string val1 = ((edittext)findviewbyid(r.id.input2)).gettext().tostring();         int num2 = integer.valueof(val1);         }         private void display(int number) {             textview quantitytextview = (textview) findviewbyid(                     r.id.quantity_text_view);             quantitytextview.settext("" + number);         }     /*for getting input values variable**/        /* adding input numbers**/         public void add(view view){             qty = num1 + num2;             display(qty);          } /*for subtracting 2 input numbs**/         public void subtract(view view){             qty = num1 - num2;             display(qty);         }         public void divide(view view){             qty = num1 / num2;             display(qty);         }         public void multiply(view view){             qty = num1 * num2;             display(qty);         }     } 

the code got crashed when ran on device through android studio. have doubt in code because i'm beginner in coding. pls find error in it.the program takes 2 input numbers , performs actions adding,subtracting,dividing , multiplying. shows output textview below.the program ran in computer crashed on device. no errors shown while running.

string val = ((edittext)findviewbyid(r.id.input1)).gettext().tostring(); 

you have move oncreate


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -