Android Question TabStripViewPager

DawningTruth

Active Member
Licensed User
My B4A was working fine. I recently upgraded.

Now it will not run TabStripPageViewer.

I get the following error message from the attached sample code:

java.lang.ClassNotFoundException: android.support.v4$view$ViewPager$OnPageChangeListener
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.createEvent(JavaObject.java:252)
at anywheresoftware.b4j.object.JavaObject.CreateEventFromUI(JavaObject.java:222)
at b4a.example.webbrowser._setuppagechangelistener(webbrowser.java:1812)
at b4a.example.webbrowser._activity_resume(webbrowser.java:1796)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at b4a.example.webbrowser.afterFirstLayout(webbrowser.java:112)
at b4a.example.webbrowser.access$000(webbrowser.java:19)
at b4a.example.webbrowser$WaitForLayout.run(webbrowser.java:84)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)


Any thoughts on what to do?
 

Attachments

  • TabStrip.zip
    12.5 KB · Views: 292

walterf25

Expert
Licensed User
Longtime User
Open up the SDK Manager and search for ViewPager and install.

Walter
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

DawningTruth

Active Member
Licensed User
Thx @Erel

Tried the advice provided.

It now works with the standard example project.

When I add in support for Page Change Listening, the error recurs.

B4X:
    Dim jo As JavaObject = TabStrip1
    Dim event As Object = jo.CreateEventFromUI("android.support.v4.view.ViewPager.OnPageChangeListener", "PageChangeListener", Null)
    jo.GetFieldJO("tabStrip").RunMethod("setOnPageChangeListener", Array(event))
    
    
    Sub PageChangeListener_Event (MethodName As String, Args() As Object) As Object
    'Log("Method: " & MethodName)
    
    If MethodName = "onPageSelected" Then
        Log("Method: " & MethodName)
        Dim ArgsList As List = Args
        Log ("Index: "&ArgsList.Get(0))
        'Log("Args: " & ArgsList)
    End If
    
    'Log("Current Position: "&currentPosition)
    
    Return Null
End Sub

Here is the error:


*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
after
Error occurred on line: 74 (Main)
java.lang.ClassNotFoundException: android.support.v4$view$ViewPager$OnPageChangeListener
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.createEvent(JavaObject.java:252)
at anywheresoftware.b4j.object.JavaObject.CreateEventFromUI(JavaObject.java:222)
at b4a.example3.main$ResumableSub_Activity_Create.resume(main.java:661)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1705)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

** Activity (main) Pause, UserClosed = true **

This is the line 74 referred to in the error:

B4X:
Dim event As Object = jo.CreateEventFromUI("android.support.v4.view.ViewPager.OnPageChangeListener", "PageChangeListener", Null)

I have tried to run the Jetifier but it gives me the following:



And the file is in the Additional Libraries folder:


Any other suggestions?
 
Upvote 0

DawningTruth

Active Member
Licensed User
@Erel It's absolutely necessary as it forms the core of my app. Have already spent months using this code to build a customer lazy loader for the TabStrip. I need to track swipe directions, which tab is currently active and a whole host of other actions. It is a couple of thousand lines of code.

And I'm speaking to investors next week to show them the first demo of my app. No pressure

It was based on this original code:


I went through the source on my main app again and these are the specific events I'm using:

B4X:
Sub PageChangeListener_Event (MethodName As String, Args() As Object) As Object
    
    'Handle Scroll event
    If MethodName = "onPageScrolled" Then
            
    '###### Process onPageScrolled Data Here ######
        
    End If
    
    'Handle Page Change Event
    If MethodName = "onPageSelected" Then
            
    '###### Process onPageSelected Events Here ######
            
    End If
    
    Return Null

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…