Android Question B4xpages problem, Java code

james_sgp

Active Member
Licensed User
Longtime User
Hi, I have the following code working fine in a non B4xpages app, but trying to use it in a B4xpages app I`m getting an error. The code is:

B4X:
Sub GetRndNonRepeatingList(lSize As Int, rnMin As Int, rnMax As Int) As List
    Dim llist As List
    Dim nr As Int
    llist.Initialize
    Private nNativeMe As JavaObject
    nNativeMe.InitializeContext
    If rnMax+1>=lSize And rnMin<rnMax Then
        Do While llist.Size< lSize
            nr=nNativeMe.RunMethod("GetRndJAVAInt", Array(rnMin,rnMax))
            If llist.IndexOf(nr)=-1 Then
                llist.Add(nr)
            End If
        Loop
    End If
    Return llist
End Sub

#If JAVA
import java.util.Random;
Public static int GetRndJAVAInt(int Min, int Max) {
    Random random = new Random();
    Return random.nextInt((Max - Min) + 1) + min;
}
#End If

Which is giving me the error:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 350 (B4XMainPage)
java.lang.RuntimeException: Method: GetRndJAVAInt not found in: raid.quiz2.main
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
    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:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at raid.quiz2.b4xmainpage._getrndnonrepeatinglist(b4xmainpage.java:442)
    at raid.quiz2.b4xmainpage._build_question_list(b4xmainpage.java:412)
    at raid.quiz2.b4xmainpage._g2_cat2_click(b4xmainpage.java:942)
    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:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7869)
    at android.widget.TextView.performClick(TextView.java:14958)
    at android.view.View.performClickInternal(View.java:7838)
    at android.view.View.access$3600(View.java:886)
    at android.view.View$PerformClick.run(View.java:29362)
    at android.os.Handler.handleCallback(Handler.java:883)

I can`t for the life of me see what I`m doing wrong...

Thanks in advance, James
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hi, I have the following code working fine in a non B4xpages app, but trying to use it in a B4xpages app I`m getting an error. The code is:

B4X:
Sub GetRndNonRepeatingList(lSize As Int, rnMin As Int, rnMax As Int) As List
    Dim llist As List
    Dim nr As Int
    llist.Initialize
    Private nNativeMe As JavaObject
    nNativeMe.InitializeContext
    If rnMax+1>=lSize And rnMin<rnMax Then
        Do While llist.Size< lSize
            nr=nNativeMe.RunMethod("GetRndJAVAInt", Array(rnMin,rnMax))
            If llist.IndexOf(nr)=-1 Then
                llist.Add(nr)
            End If
        Loop
    End If
    Return llist
End Sub

#If JAVA
import java.util.Random;
Public static int GetRndJAVAInt(int Min, int Max) {
    Random random = new Random();
    Return random.nextInt((Max - Min) + 1) + min;
}
#End If

Which is giving me the error:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 350 (B4XMainPage)
java.lang.RuntimeException: Method: GetRndJAVAInt not found in: raid.quiz2.main
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
    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:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at raid.quiz2.b4xmainpage._getrndnonrepeatinglist(b4xmainpage.java:442)
    at raid.quiz2.b4xmainpage._build_question_list(b4xmainpage.java:412)
    at raid.quiz2.b4xmainpage._g2_cat2_click(b4xmainpage.java:942)
    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:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7869)
    at android.widget.TextView.performClick(TextView.java:14958)
    at android.view.View.performClickInternal(View.java:7838)
    at android.view.View.access$3600(View.java:886)
    at android.view.View$PerformClick.run(View.java:29362)
    at android.os.Handler.handleCallback(Handler.java:883)

I can`t for the life of me see what I`m doing wrong...

Thanks in advance, James
I had something similar:

RBS
 
Upvote 0
Top