The main request is for advice on the backendless code required to populate an activity in android studio using a table from backendless.
In this example there is a separate activity in which staff will post messages and these will automatically populate a table called ‘Message’.
There is a separate activity which when clicked on I would like to then collect the ‘Message’ table and then it is displayed in a list view.
It seems to work fine when hard coded so suspect I am doing something wrong when trying to access the table from backendless.
I think I am missing a where clause, the only tutorial example I can find uses a where clause that specifically makes it so the user can only see their own ‘Message’ they will have posted where as I want it so that all users can see all items in the ‘Message’ table (and currently it is in “date” (a column of the Message table) order).
Is there a generic where clause that shows all the table to all users?
Issues like having a custom message class, having an adapter to set the class values and its layout have been done i believe as other activities use these without issues.
I will copy the code in the activity in question (called MessageBoard), when from the MainActivity the MessageBoard is accessed (via a button) an error “app name, has stopped working” comes up when testing it.
code :
public class MessageBoard extends AppCompatActivity {
I added this line at the top of the activity : private static final String TAG = “MessageBoard”;
When i run the app im not sure it is recognizing the logs above because when i search for them they are not there the only red things in the logcat are;
Which from a google search the seems to be more related to the emulator than anything in the code.
It seems to suggest I need to be changing the GPU from hardware to software but in the AVD settings it is set to automatic and is not changeable
You should try to do what google advises. You need to ensure that you can see the logs. Only then will it be possible to understand what the problem is.
Hi there I think I have found the error in the logcat it is as below:
A quick google search seems to indicate that some aspect of my code hasn’t been initialized but I cant find which it is after trying a few variations, any thoughts based on the error message below?
2020-10-26 13:04:27.929 12701-12701/com.harding.contactsapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.harding.contactsapp, PID: 12701
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.harding.contactsapp/com.harding.BalmoralDoctorsTest.MessageBoard}: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.view.View.setVisibility(int)’ on a null object reference
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.NullPointerException: Attempt to invoke virtual method ‘void android.view.View.setVisibility(int)’ on a null object reference
at com.harding.BalmoralDoctorsTest.MessageBoard.showProgress(MessageBoard.java:88)
at com.harding.BalmoralDoctorsTest.MessageBoard.onCreate(MessageBoard.java:49)
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)
java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.view.View.setVisibility(int)’ on a null object reference.
I would suggest you to inspect the code and find the place where you call setVisibility method.
My assumption - maybe you try to change the visibility of view that hasn’t been initialized.
Hi Maksym
Thank you for your answer, the setVisibility method was used as part of a progress bar used when moving between two activities (MainActivity and MessageBoard), it was non essential and thus removed and the error is gone.
But now there is a new error that wasnt there before:
java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.ListView.setAdapter(android.widget.ListAdapter)’ on a null object reference
which presumably has a similar logic (in this case that the setAdapter method is not initialized).
The setAdapter appears in the handleResponse aspect of the code below
Can you see in the below what needs to be done to initialize the setAdapter method?
public class MessageBoard extends AppCompatActivity {
Attempt to invoke virtual method ‘setAdapter’ on a null object reference
You try to invoke setAdapter on a null object (which is lvList).
The onCreate method is not the best place to operate views. It’s fundamentals of Android development. I suggest you to take any Android Development course (there a lot of free information on the internet).and practice a little bit.