This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
I am exploring startActivityForResult. I am using a self-study book.
* MainActivity starts ActivityC for a result. The method onClickGetData accomplishes this.
* ActivityC returns the text typed into an EditText. The method onClickSendData does this.
* MainActivity receives the data and displays it in a TextView.
However, when I tap "Send Data" in ActivityC the app crashes ("Unfortunately app has stopped working").
I am using Android Studio. In the original code from the self-study book everything is inside the onCreate method and uses inner classes to implement the button handlers.
My button handlers are outside the onCreate method so I've had to declare the TextView and EditView variables as class variables because they are used in multiple methods. I'm wondering whether these changes are causing the app to crash.
I would start by looking at LogCat to see what it shows.
posted 1 month ago
Good Morning Ron,
OK so, LogCat reveals the following pertinent lines:
01-23 03:19:29.331 7860-7860/com.example.hour2appversion2 E/AndroidRuntime: FATAL EXCEPTION: main
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at java.lang.reflect.Method.invoke(Native Method)
It seems there is NullPointerException:
* Line 14 in the code listed in the post (but line 24 in the actual code) the the EditText object "e" is set to null
But how can this be, since I have declared e has an EditText object and assigned it in line 9 of Class ActivityC ?
It is 3.30 am in England so I will act on any replies tomorrow. Thanks.