Android Question Java Object Usage

androh

Member
Licensed User
Longtime User
Hello,
For select a list item in list view, I want to use this java code in b4a with java object.
Code:
Listview.getAdapter().getView(Index, null, null).performClick();

Code:
    Dim jo As JavaObject = LstView
    jo=jo.RunMethodJO("getAdapter", Null)
    jo=jo.RunMethodJO("getView", Array(Index, Null, Null))
    jo.RunMethod("performClick", Null)

But B4A gives this error:
Code:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_lstclick (B4A line: 268)
jo=jo.RunMethodJO("getView", Array(Index, Null, Null)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:137)
    at b4a.example.main._lstclick(main.java:710)
    at b4a.example.main._pnltest_touch(main.java:778)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at anywheresoftware.b4a.BA$2.run(BA.java:299)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5253)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.ViewGroup.getContext()' on a null object reference
    at anywheresoftware.b4a.objects.SimpleListAdapter.getView(SimpleListAdapter.java:85)
    ... 18 more
java.lang.reflect.InvocationTargetException

What can I do with this issue?
 
Last edited:
Hi Erel,
I've wanted to use this code for highlight default item in listview at application startup. In my listview, checked item is highlighted.
Anyway I found a other solution. I used this code for highlight any item in listview.
Have a nice day.

Code:
Sub SetLstColor (Index As Int, Color As Int)
  
    Dim jo As JavaObject = LstView
    jo.RunMethodJO("getChildAt", Array(Index)).RunMethod("setBackgroundColor", Array(Color))
  
End Sub
 
Last edited:
Upvote 0
Back
Top