1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps Textfield

Discussion in 'Android Development' started by Wouter Schurgers, Sep 9, 2019.

  1. Wouter Schurgers

    Thread Starter

    Hey,

    Kan iemand mij helpen met deze oefening?(zie bijlage)

    Ik snap niet hoe je een textfield invoegd.

    Alvast bedankt!

    Groeten Wouter

     

    Attached Files:


    Advertisement

  2. Best Answer:
    Post #15 by wseng92, Sep 23, 2019 (1 points)
  3. kate

    kate Dreaming of Bugdroid.
    Moderator

    Welcome to the site Wouter :)

    This is an English forum, if you don't know English you can use Google Translate:
    https://translate.google.com/


    Translated:
    Can someone help me with this exercise (see attachment)

    I don't understand how to insert a textfield.

    Thanks in advance!
     
    Steven58 likes this.
  4. Greum

    Greum Well-Known Member

    You might find you'll get more help if you post your code as text rather than a photograph.
     
  5. Wouter Schurgers

    Thread Starter

    Hey

    Can someone help me with this exercise (see attachment)

    I don't understand how to insert a textfield.
    (I am a beginner)

    Thanks in advance!
    (I hope you understand)

    Greetings Wouter
     

    Attached Files:

  6. kate

    kate Dreaming of Bugdroid.
    Moderator

    To post code on this forum:

    [CODE]
    Your
    Code
    Here
    [/CODE]


    Here is the code from your attached document:
    Code (Text):
    1. package com.example.oefenjava2;
    2. import androidx.appcompat.app.AppCompatActivity;
    3. import android.os.Bundle;
    4. import android.widget.EditText;
    5. import android.widget.TextView;
    6. public class MainActivity extends AppCompatActivity {
    7.     String rechtKinderbijslag;
    8.     int leeftijd = 22;
    9.     @Override
    10.     protected void onCreate(Bundle savedInstanceState) {
    11.         super.onCreate(savedInstanceState);
    12.         setContentView(R.layout.activity_main);
    13.        
    14.         if (leeftijd < 18) {
    15.             rechtKinderbijslag = "wel recht op kinderbijslag";
    16.         } else {
    17.             rechtKinderbijslag = "geen recht op kinderbijslag";
    18.         }
    19.         TextView myTextView = (TextView)findViewById(R.id.textview);
    20.         myTextView.setText(rechtKinderbijslag);
    21.     }
    22. }
     
    GameTheory likes this.
  7. Wouter Schurgers

    Thread Starter

    1. package com.example.oefenjava2;
    2. import androidx.appcompat.app.AppCompatActivity;
    3. import android.os.Bundle;
    4. import android.widget.EditText;
    5. import android.widget.TextView;
    6. public class MainActivity extends AppCompatActivity {
    7. String rechtKinderbijslag;
    8. int leeftijd = 22;
    9. @override
    10. protected void onCreate(Bundle savedInstanceState) {
    11. super.onCreate(savedInstanceState);
    12. setContentView(R.layout.activity_main);
    13. if (leeftijd < 18) {
    14. rechtKinderbijslag = "wel recht op kinderbijslag";
    15. } else {
    16. rechtKinderbijslag = "geen recht op kinderbijslag";
    17. }
    18. TextView myTextView = (TextView)findViewById(R.id.textview);
    19. myTextView.setText(rechtKinderbijslag);
    20. }
    21. }


    It will of course only become really interesting if the app user can enter his / her age himself. The app then shows whether the person is of age. Add this option. You can use an EditText for this. (sorry if it is translated incorrectly)
     
  8. wseng92

    wseng92 Android Enthusiast

    Use EditText.
     
  9. Wouter Schurgers

    Thread Starter

    Hey,

    What am I doing wrong with this code, he keeps saying app stops,

    thank you in advance!

    Greetings Wouter.

    package com.example.kak;

    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.EditText;
    import android.widget.TextView;

    public class MainActivity extends AppCompatActivity {
    String childBenefit;
    int age;



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

    EditText editAge = (EditText) findViewById(R.id.editText);
    age = Integer.parseInt(editAge.getText().toString());



    if( age < 18) {
    childBenefit = "entitled to child benefit";
    } else {
    childBenefit = "no entitlement to child benefit";

    }
    TextView myTextView = (TextView)findViewById(R.id.textview);
    myTextView.setText(childBenefit);
    }
    }
     
  10. wseng92

    wseng92 Android Enthusiast

    Please post stacktrace. You can find it on logcat tab.
     
  11. Wouter Schurgers

    Thread Starter

    you mean this?

    2019-09-20 20:04:47.508 6341-6341/? I/zygote: Not late-enabling -Xcheck:jni (already on)
    2019-09-20 20:04:47.541 6341-6341/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/lib/x86, /system/lib, /vendor/lib]]
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:93)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.663 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.664 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/lib/x86, /system/lib, /vendor/lib]]
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:93)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.665 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.666 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.kak-7pqLwDYU6E5fSFHEEZ0WoA==/lib/x86, /system/lib, /vendor/lib]]
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:93)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void androidx.core.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:647)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:790)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:730)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:863)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:824)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:515)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:423)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void com.example.kak.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:17)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.os.Looper.loop() (Looper.java:164)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.Zygote$MethodAndArgsCaller.run() (Zygote.java:240)
    2019-09-20 20:04:47.667 6341-6341/com.example.kak I/zygote: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:767)
    2019-09-20 20:04:47.757 6341-6341/com.example.kak D/AndroidRuntime: Shutting down VM
    2019-09-20 20:04:47.759 6341-6341/com.example.kak E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.kak, PID: 6341
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kak/com.example.kak.MainActivity}: java.lang.NumberFormatException: For input string: ""
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.NumberFormatException: For input string: ""
    at java.lang.Integer.parseInt(Integer.java:620)
    at java.lang.Integer.parseInt(Integer.java:643)
    at com.example.kak.MainActivity.onCreate(MainActivity.java:20)
    at android.app.Activity.performCreate(Activity.java:6975)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     
    wseng92 likes this.
  12. wseng92

    wseng92 Android Enthusiast

    Yes. Can you post your xml layout as well?
     
  13. Wouter Schurgers

    Thread Starter

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="96dp"
    android:layout_marginLeft="96dp"
    android:layout_marginTop="144dp"
    android:layout_marginEnd="102dp"
    android:layout_marginRight="102dp"
    android:layout_marginBottom="542dp"
    android:ems="10"
    android:hint="@String/age"
    android:importantForAutofill="no"
    android:inputType="number"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.571" />


    </androidx.constraintlayout.widget.ConstraintLayout>
     
  14. wseng92

    wseng92 Android Enthusiast

    Did it crash after this line removed?

    Code (Java):
    1. age = Integer.parseInt(editAge.getText().toString());
     
  15. Wouter Schurgers

    Thread Starter

    When i remove this line it doesn't crach.
     
  16. wseng92

    wseng92 Android Enthusiast

    It crashed because int cannot hold an empty String. You can use TextWatcher to check the number entered by user.

    Code (Java):
    1. public class MainActivity extends AppCompatActivity {
    2.     String childBenefit;
    3.     int age;
    4.     TextView myTextView;
    5.  
    6.     @Override
    7.     protected void onCreate(Bundle savedInstanceState) {
    8.         super.onCreate(savedInstanceState);
    9.         setContentView(R.layout.activity_main);
    10.  
    11.         final EditText editAge = (EditText) findViewById(R.id.editText);
    12.         myTextView = (TextView) findViewById(R.id.textview);
    13.  
    14.         editAge.addTextChangedListener(new TextWatcher() {
    15.             @Override
    16.             public void onTextChanged(CharSequence s, int start, int before, int count) {
    17.                 // TODO Auto-generated method stub
    18.                 if (!editAge.getText().toString().equals("")) {
    19.                     checkAge(Integer.parseInt(editAge.getText().toString()));
    20.                 }
    21.             }
    22.  
    23.             @Override
    24.             public void afterTextChanged(Editable editable) {
    25.  
    26.             }
    27.  
    28.             @Override
    29.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    30.                 // TODO Auto-generated method stub
    31.             }
    32.  
    33.         });
    34.     }
    35.  
    36.     public void checkAge(int age) {
    37.         if (age < 18) {
    38.             childBenefit = "entitled to child benefit";
    39.         } else {
    40.             childBenefit = "no entitlement to child benefit";
    41.         }
    42.         myTextView.setText(childBenefit);
    43.     }
    44. }
     
  17. Wouter Schurgers

    Thread Starter

    Ok it works, thanks verry much for your response,
    helped me a lot.
    Greetings Wouter
     
  18. wseng92

    wseng92 Android Enthusiast

Loading...

Share This Page

Loading...