android.support.constraint.ConstraintLayout cannot be cast to android.widget.EditText [closed]












-2















I am new in Android Studio and I just started my first app.
my app is crashing from an unknown reason, hope you will help me to fix it



--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ronz2.myfirstapp, PID: 3096
java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.ronz2.myfirstapp.MainActivity$1.onClick(MainActivity.java:21)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the MainActivity code:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button addBtn = (Button) findViewById(R.id.addBtn);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);
TextView resultTextView = (TextView) findViewById(R.id.resultTextView);

int num1 = Integer.parseInt(firstNumEditText.getText().toString());
int num2 = Integer.parseInt(secondNumEditText.getText().toString());
int result = num1 + num2;

resultTextView.setText(result + "");
}
});
}









share|improve this question















closed as off-topic by Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub Nov 19 '18 at 3:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1





    Add your MainActivity code here, So that I can help easily?

    – Anil Ghodake
    Nov 17 '18 at 10:03











  • share some code

    – Radesh
    Nov 17 '18 at 10:07






  • 1





    This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

    – Wayne Phipps
    Nov 17 '18 at 10:45






  • 1





    Post your activity's xml

    – forpas
    Nov 17 '18 at 16:39
















-2















I am new in Android Studio and I just started my first app.
my app is crashing from an unknown reason, hope you will help me to fix it



--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ronz2.myfirstapp, PID: 3096
java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.ronz2.myfirstapp.MainActivity$1.onClick(MainActivity.java:21)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the MainActivity code:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button addBtn = (Button) findViewById(R.id.addBtn);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);
TextView resultTextView = (TextView) findViewById(R.id.resultTextView);

int num1 = Integer.parseInt(firstNumEditText.getText().toString());
int num2 = Integer.parseInt(secondNumEditText.getText().toString());
int result = num1 + num2;

resultTextView.setText(result + "");
}
});
}









share|improve this question















closed as off-topic by Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub Nov 19 '18 at 3:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1





    Add your MainActivity code here, So that I can help easily?

    – Anil Ghodake
    Nov 17 '18 at 10:03











  • share some code

    – Radesh
    Nov 17 '18 at 10:07






  • 1





    This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

    – Wayne Phipps
    Nov 17 '18 at 10:45






  • 1





    Post your activity's xml

    – forpas
    Nov 17 '18 at 16:39














-2












-2








-2








I am new in Android Studio and I just started my first app.
my app is crashing from an unknown reason, hope you will help me to fix it



--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ronz2.myfirstapp, PID: 3096
java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.ronz2.myfirstapp.MainActivity$1.onClick(MainActivity.java:21)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the MainActivity code:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button addBtn = (Button) findViewById(R.id.addBtn);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);
TextView resultTextView = (TextView) findViewById(R.id.resultTextView);

int num1 = Integer.parseInt(firstNumEditText.getText().toString());
int num2 = Integer.parseInt(secondNumEditText.getText().toString());
int result = num1 + num2;

resultTextView.setText(result + "");
}
});
}









share|improve this question
















I am new in Android Studio and I just started my first app.
my app is crashing from an unknown reason, hope you will help me to fix it



--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ronz2.myfirstapp, PID: 3096
java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.ronz2.myfirstapp.MainActivity$1.onClick(MainActivity.java:21)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


This is the MainActivity code:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button addBtn = (Button) findViewById(R.id.addBtn);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);
TextView resultTextView = (TextView) findViewById(R.id.resultTextView);

int num1 = Integer.parseInt(firstNumEditText.getText().toString());
int num2 = Integer.parseInt(secondNumEditText.getText().toString());
int result = num1 + num2;

resultTextView.setText(result + "");
}
});
}






android crash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 16:37







Ron Zaretsky

















asked Nov 17 '18 at 10:02









Ron ZaretskyRon Zaretsky

33




33




closed as off-topic by Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub Nov 19 '18 at 3:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub Nov 19 '18 at 3:03


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Vega, sideshowbarker, jww, Pearly Spencer, Paul Roub

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1





    Add your MainActivity code here, So that I can help easily?

    – Anil Ghodake
    Nov 17 '18 at 10:03











  • share some code

    – Radesh
    Nov 17 '18 at 10:07






  • 1





    This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

    – Wayne Phipps
    Nov 17 '18 at 10:45






  • 1





    Post your activity's xml

    – forpas
    Nov 17 '18 at 16:39














  • 1





    Add your MainActivity code here, So that I can help easily?

    – Anil Ghodake
    Nov 17 '18 at 10:03











  • share some code

    – Radesh
    Nov 17 '18 at 10:07






  • 1





    This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

    – Wayne Phipps
    Nov 17 '18 at 10:45






  • 1





    Post your activity's xml

    – forpas
    Nov 17 '18 at 16:39








1




1





Add your MainActivity code here, So that I can help easily?

– Anil Ghodake
Nov 17 '18 at 10:03





Add your MainActivity code here, So that I can help easily?

– Anil Ghodake
Nov 17 '18 at 10:03













share some code

– Radesh
Nov 17 '18 at 10:07





share some code

– Radesh
Nov 17 '18 at 10:07




1




1





This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

– Wayne Phipps
Nov 17 '18 at 10:45





This is the clue ConstraintLayout cannot be cast to android.widget.EditText.

– Wayne Phipps
Nov 17 '18 at 10:45




1




1





Post your activity's xml

– forpas
Nov 17 '18 at 16:39





Post your activity's xml

– forpas
Nov 17 '18 at 16:39












1 Answer
1






active

oldest

votes


















0














If this is the only relevant code then one of these ids: firstNumEditText or secondNumEditText does not belong to an EditText but to a ConstraintLayout.



So one of these lines:



EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);


throws the exception, because you are trying to cast a ConstraintLayout to an EditText.


Check any ConstraintLayout's id in your xml that matches with these 2 ids and change it.






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If this is the only relevant code then one of these ids: firstNumEditText or secondNumEditText does not belong to an EditText but to a ConstraintLayout.



    So one of these lines:



    EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
    EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);


    throws the exception, because you are trying to cast a ConstraintLayout to an EditText.


    Check any ConstraintLayout's id in your xml that matches with these 2 ids and change it.






    share|improve this answer




























      0














      If this is the only relevant code then one of these ids: firstNumEditText or secondNumEditText does not belong to an EditText but to a ConstraintLayout.



      So one of these lines:



      EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
      EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);


      throws the exception, because you are trying to cast a ConstraintLayout to an EditText.


      Check any ConstraintLayout's id in your xml that matches with these 2 ids and change it.






      share|improve this answer


























        0












        0








        0







        If this is the only relevant code then one of these ids: firstNumEditText or secondNumEditText does not belong to an EditText but to a ConstraintLayout.



        So one of these lines:



        EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
        EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);


        throws the exception, because you are trying to cast a ConstraintLayout to an EditText.


        Check any ConstraintLayout's id in your xml that matches with these 2 ids and change it.






        share|improve this answer













        If this is the only relevant code then one of these ids: firstNumEditText or secondNumEditText does not belong to an EditText but to a ConstraintLayout.



        So one of these lines:



        EditText firstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
        EditText secondNumEditText = (EditText) findViewById(R.id.secondNumEditText);


        throws the exception, because you are trying to cast a ConstraintLayout to an EditText.


        Check any ConstraintLayout's id in your xml that matches with these 2 ids and change it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 16:44









        forpasforpas

        10.4k1421




        10.4k1421















            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)