Android Question Implementing a compass (Lib NewCompassView)

prokli

Active Member
Licensed User
Longtime User
I try to run this nice compass app:
https://www.b4x.com/android/forum/threads/compassview-another-compassview.93977/

Whenever program tries to load the layout "main" (line 3)
B4X:
 Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
 
    mbm1.Initialize(File.DirAssets, "ic_needle_2.png")
    bmd1.Initialize(mbm1)
 
    ncv1.DegreesColor = Colors.Yellow
    ncv1.BorderColor = Colors.White
    ncv1.DegreeValueColor = Colors.Red
    ncv1.OrientationLabelsColor = Colors.Magenta
    ncv1.ShowBorder = True
    ncv1.ShowDegreeValue = True
    ncv1.ShowOrientationLabels = True
    ncv1.DegreesStep = 5
    ncv1.Needle = bmd1


I get an error message. I have added the libraries to the AdditionalLib folder and "NewCompassView" can be added as a CustomView by the Designer.
So, what do I wrong??

Logger verbunden mit: samsung SM-G928F
--------- beginning of main
Copying updated assets files (11)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 37 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at JHS.NewCompassView.main._activity_create(main.java:398)
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 JHS.NewCompassView.main.afterFirstLayout(main.java:105)
at JHS.NewCompassView.main.access$000(main.java:17)
at JHS.NewCompassView.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 18 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:202)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2968)
at android.content.res.Resources.getLayout(Resources.java:1984)
at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
at edu.arbelkilani.compass.Compass.init(Compass.java:89)
at edu.arbelkilani.compass.Compass.<init>(Compass.java:66)
at newcompassviewwrapper.newcompassviewWrapper._initialize(newcompassviewWrapper.java:81)
... 21 more
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 37 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at JHS.NewCompassView.main._activity_create(main.java:398)
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 JHS.NewCompassView.main.afterFirstLayout(main.java:105)
at JHS.NewCompassView.main.access$000(main.java:17)
at JHS.NewCompassView.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 18 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:202)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2968)
at android.content.res.Resources.getLayout(Resources.java:1984)
at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
at edu.arbelkilani.compass.Compass.init(Compass.java:89)
at edu.arbelkilani.compass.Compass.<init>(Compass.java:66)
at newcompassviewwrapper.newcompassviewWrapper._initialize(newcompassviewWrapper.java:81)
... 21 more
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 37 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
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)
.............................................................
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi:

As you can see, you get an error in: Error occurred on line: 37 (Main) (you should have posted that line of code).

This line is:
B4X:
Activity.LoadLayout("main")

So, you have a problem loading the layout. Open the layout, probably there's some problem with some file that doesn't exist. ( Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0 )

Do you have the ic_needle.png files?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
make sure to copy the res folder to your app and reference it in your code. See example code.
 
Upvote 0

prokli

Active Member
Licensed User
Longtime User
I am using excactly the code of this example:
https://www.b4x.com/android/forum/threads/compassview-another-compassview.93977/

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aNewCompassView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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.

    Private ncv1, ncv2, ncv3 As NewCompassView
    
    Private mbm1, mbm2, mbm3 As Bitmap
    Private bmd1, bmd2, bmd3 As BitmapDrawable
    
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    
    mbm1.Initialize(File.DirAssets, "ic_needle_2.png")
    bmd1.Initialize(mbm1)
    
    ncv1.DegreesColor = Colors.Yellow
    ncv1.BorderColor = Colors.White
    ncv1.DegreeValueColor = Colors.Red
    ncv1.OrientationLabelsColor = Colors.Magenta
    ncv1.ShowBorder = True
    ncv1.ShowDegreeValue = True
    ncv1.ShowOrientationLabels = True
    ncv1.DegreesStep = 5
    ncv1.Needle = bmd1
    
    'second compass
    mbm2.Initialize(File.DirAssets, "ic_needle_1.png")
    bmd2.Initialize(mbm2)
    
    ncv2.DegreesColor = Colors.Cyan
    ncv2.BorderColor = Colors.Green
    ncv2.DegreeValueColor = Colors.White
    ncv2.OrientationLabelsColor = Colors.Blue
    ncv2.ShowBorder = True
    ncv2.ShowDegreeValue = True
    ncv2.ShowOrientationLabels = True
    ncv2.DegreesStep = 15
    ncv2.Needle = bmd2
    
    'third compass
    mbm3.Initialize(File.DirAssets, "ic_needle.png")
    bmd3.Initialize(mbm3)
    
    ncv3.DegreesColor = Colors.White
    ncv3.BorderColor = Colors.White
    ncv3.DegreeValueColor = Colors.White
    ncv3.OrientationLabelsColor = Colors.White
    ncv3.ShowBorder = True
    ncv3.ShowDegreeValue = True
    ncv3.ShowOrientationLabels = False
    ncv3.DegreesStep = 45
    ncv3.Needle = bmd3

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ncv1_sensor_changed(value As Double)
    
    Log("Compass 1  = " & value)
    
End Sub

Sub ncv2_sensor_changed(value As Double)
    
    Log("Compass 2  = " & value)
    
End Sub

Sub ncv3_sensor_changed(value As Double)
    
    Log("Compass 3  = " & value)
    
End Sub

When executing the code " Activity.LoadLayout("main")" the program crashes. I know that the app uses a CustomView which is provided by a library (Jar/xml). I put these files to the AdditionalFolder. I supposet that I have to do some copy work concerning the expression "#AdditionalRes: ..\LibRes"
But I don't know to which location
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
#AdditionalRes: ..\LibRes
Did you copy the Folder LibRes to your project folder? Seems that not?

Edit: I´m sure you did not. I just tried the example project on my Andoid 11 Device and it works fine here. SURELY i did copy the LibResFolder to my project.
 
Last edited:
Upvote 0

prokli

Active Member
Licensed User
Longtime User
I modified the manifest file and I copied the LibRes to my project folder. Project still crashes.
See attached project
 

Attachments

  • NewCompassViewHK.zip
    29.9 KB · Views: 192
Upvote 0

prokli

Active Member
Licensed User
Longtime User
Did you copy the Folder LibRes to your project folder? Seems that not?

Edit: I´m sure you did not. I just tried the example project on my Andoid 11 Device and it works fine here. SURELY i did copy the LibResFolder to my project.
I did!
 
Upvote 0

semar

Active Member
Licensed User
Longtime User
Same problem here, tested on two different smartphones.
B4X:
Logger connected to:  samsung SM-N910F
--------- beginning of main
SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=JHS.NewCompassView
TimaSignature is unavailable
Added TimaKeyStore provider
ClassLoader referenced unknown path: /data/app/JHS.NewCompassView-1/lib/arm
common created.
Starting remote logger. Port: 8495
#1 mView = com.android.internal.policy.PhoneWindow$DecorView{ab64560 I.E...... R.....ID 0,0-0,0}
--------- beginning of system
Metadata value : none
Use EGL_SWAP_BEHAVIOR_PRESERVED: true
QUALCOMM build                   : d842ad3, Ia10634f51b
Build Date                       : 01/04/16
OpenGL ES Shader Compiler Version: XE031.06.00.05
Local Branch                     : mybranch17578993
Remote Branch                    : quic/LA.BF.2.1.2_rb1.7
Remote Branch                    : NONE
Reconstruct Branch               : NOTHING
eglInitialize EGLDisplay = 0xadf7e7c4
Initialized EGL, version 1.4
After accept
*** Debugger waiting for connection (0) ***
MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
DTS_GLAPI : DTS is not allowed for Package : JHS.NewCompassView
Metadata value : none
#1 mView = android.widget.LinearLayout{bf8b942 V.E...... ......I. 0,0-0,0 #10203b0 android:id/toast_layout_root}
MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
*** Debugger waiting for connection (1) ***
Copying updated assets files (4)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
setTypeface with style : 0
setTypeface with style : 0
setTypeface with style : 0
init function
registerListener :: 1937338482, Orientation Sensor, 20000, 0,
Error occurred on line: 37 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at JHS.NewCompassView.main._activity_create(main.java:398)
    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 JHS.NewCompassView.main.afterFirstLayout(main.java:105)
    at JHS.NewCompassView.main.access$000(main.java:17)
    at JHS.NewCompassView.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7225)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 18 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
    at edu.arbelkilani.compass.Compass.updateNeedle(Compass.java:162)
    at edu.arbelkilani.compass.Compass.init(Compass.java:114)
    at edu.arbelkilani.compass.Compass.<init>(Compass.java:66)
    at newcompassviewwrapper.newcompassviewWrapper._initialize(newcompassviewWrapper.java:81)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/JHS.NewCompassView-1/base.apk"],nativeLibraryDirectories=[/data/app/JHS.NewCompassView-1/lib/arm, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 25 more
    Suppressed: java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 26 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
null: 15
** Activity (main) Resume **
java.net.SocketException: Socket closed
    at libcore.io.Posix.recvfromBytes(Native Method)
    at libcore.io.Posix.recvfrom(Posix.java:189)
    at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:250)
    at libcore.io.IoBridge.recvfrom(IoBridge.java:549)
    at java.net.PlainSocketImpl.read(PlainSocketImpl.java:481)
    at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
    at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
    at java.io.InputStream.read(InputStream.java:162)
    at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:149)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:234)
    at anywheresoftware.b4a.shell.ShellConnector.readControlData(ShellConnector.java:191)
    at anywheresoftware.b4a.shell.ShellConnector.connect(ShellConnector.java:186)
    at anywheresoftware.b4a.shell.ShellConnector.run(ShellConnector.java:119)
    at java.lang.Thread.run(Thread.java:818)
And yes, the folder LibRes is inside the main project folder - like the picture in an above post.
May be some library references to a .zip file no longer available ? I'm puzzled by this error log:
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/JHS.NewCompassView-1/base.apk"],nativeLibraryDirectories=[/data/app/JHS.NewCompassView-1/lib/arm, /vendor/lib, /system/lib]]

More on this, there's maybe a typo in a Library reference:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
Shouldn't be "android" instead of "Landroid" ?


Any help - expecially from the author of the example - would be really appreciated.
 
Last edited:
Upvote 0
Top