Problem with activitycreate

smasher230

Member
Licensed User
Longtime User
Hi,

Since installing B4A-Bridge I get the following error, even though my code hasn't changed since using the emulator. Can anyone suggest a solution?

An error has occurred in sub:
main_activitycreate(B4A line:43)
Activity.LoadLayout("bMain") 'Load the Layout file.
java.RuntimeException:
Don't call setOnClickListener for aan AdapterView.
You probably want setOnClickListener instead Continue?

Thanks in advance
Smasher230
 

smasher230

Member
Licensed User
Longtime User
Hi,

Thought I would attach the relevant part of the log in case it helps (note that the layout file has been renamed "main.bal"):

--------------------------snip---------------------------------------

** Activity (main) Create, isFirst = true **
main_activity_create (B4A line: 29)
Activity.LoadLayout("main")
java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
at android.widget.AdapterView.setOnClickListener(AdapterView.java:750)
at anywheresoftware.b4a.objects.ViewWrapper.innerInitialize(ViewWrapper.java:45)
at anywheresoftware.b4a.objects.ListViewWrapper.innerInitialize(ListViewWrapper.java:48)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:104)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:120)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:67)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:151)
at hcp.buddy.main._activity_create(main.java:207)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:99)
at hcp.buddy.main.afterFirstLayout(main.java:83)
at hcp.buddy.main.access$100(main.java:15)
at hcp.buddy.main$WaitForLayout.run(main.java:71)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **

-----------------------end of snip-------------------------------
Smasher230
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Did you use the Designer on the emulator via B4A-Bridge to add any ListViews?

It's only an educated guess but it looks like the layout file might be telling the layout code to do something wrong. Try removing any ListViews in the layout and then add them back without connecting to the Designer and see what happens.
 
Upvote 0

smasher230

Member
Licensed User
Longtime User
Adding listviews programmatically

Hi,

I have removed the listviews and am trying to initialise them in code. the main_activity_create code is below. There are to listviews (lstOptions and lstBuddies). Interestingly lstOptions initializes correctly, but I still get the same error when I try to initialise lstBuddies (the same java runtime exception). It seems to be declared properly in Globals and I even tried renaming it, but no luck so far:


Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
lstoptions.initialize("lstOptions")
Activity.AddView(lstOptions, 0, 170, 320, 130)
lstoptions.Color = Colors.DarkGray
lstOptions.AddSingleLine("Add New")
lstOptions.AddSingleLine("Edit")
lstOptions.AddSingleLine("Delete")
lstOptions.AddSingleLine("Get handicap")
lstBuddies.Initialize("lstBuddies")
activity.AddView(lstBuddies, 0, 0, 320, 170)
lstBuddies.Color = Colors.Green
intstartnum = 0
intendnum = 10
intstartname = 10
list1.Initialize
readlistsmash
lstOptions.Visible = False

End Sub
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
For problems like this you need to post a project that shows the error. Just looking at code fragments doesn't give enough information - for example I can't see your Dims of the ListViews and I don't know what else you are doing (or not) nor what your layout is doing.
 
Upvote 0

adamioan

Member
Licensed User
Longtime User
Hi Agraham, I have the same error with my application. I manage to spot the problem of the listview but I don't know how to fix it. In fact, the problem occurs when I add the click event sub. If I comment the whole sub, everything works great. I did remove the list view from designer and add it programmatically, but the error is still there. How can I post my application here (806 Kb zipped)
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
In the B4A Editor use this menu:

<File><Export as Zip>

That gives you a very small zip with all the necessary project files.
(By the way this function is very handy to make backups of different stages of your project.)

Rolf
 
Last edited:
Upvote 0

adamioan

Member
Licensed User
Longtime User
Never mind Agraham, I found it. The problem is at the listview Click declaration. If by mistake you set
Sub ListView1_Click instead of ListView1_ItemClick (Position As Int, Value As Object)
the above error occurs.
Here is a simple code to replicate it
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
Dim lv1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   lv1.Initialize("ListView1")
   Activity.AddView (lv1, 10, 10,200, 200)
   lv1.AddSingleLine2("List 1 Line 1", lv1.Size)
End Sub

Sub ListView1_Click
   Msgbox ("Do something", "")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Thank you anyway Agraham and rbsoft.
 
Upvote 0
Top