Android Question [SOLVED] Error when running app - java.lang.ClassNotFoundException:

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

I am getting this error cause for the app to fail. Compiled perfectly but then when opening this is what it showed as the cause line

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example.ScratchView-Vw2KbtcivT4lcTUxH-D1dA==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example.ScratchView-Vw2KbtcivT4lcTUxH-D1dA==/lib/arm64, /system/lib64, /system/vendor/lib64]]

this is the full error log

Logger connected to: samsung SM-N950F
--------- beginning of main
Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
--------- beginning of crash
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
at com.cooltechworks.views.ScratchImageView.onSizeChanged(ScratchImageView.java:172)
at android.view.View.sizeChange(View.java:22621)
at android.view.View.setFrame(View.java:22563)
at android.widget.ImageView.setFrame(ImageView.java:1201)
at android.view.View.layout(View.java:22423)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:60)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:508)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:1041)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3363)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2827)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1873)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8496)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:986)
at android.view.Choreographer.doCallbacks(Choreographer.java:764)
at android.view.Choreographer.doFrame(Choreographer.java:699)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example.ScratchView-Vw2KbtcivT4lcTUxH-D1dA==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example.ScratchView-Vw2KbtcivT4lcTUxH-D1dA==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 35 more

Any advise would be great.

Thank you

Peter
 

DonManfred

Expert
Licensed User
Longtime User
How could we help? You are providing exactly zero information about your app, your manifest, the libraries you are using.

Upload a small example that shows the problem.
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
How could we help? You are providing exactly zero information about your app, your manifest, the libraries you are using.

Upload a small example that shows the problem.

Hi
Sorry it was an app that you did previously with the Scratch and Win v1.5 of your lib and I also added the extra line for the .jar

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

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #AdditionalJar: com.android.support:support-v4
#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 ScratchImageView1 As ScratchImageView
    Private ScratchTextView1 As ScratchTextView
    Private ScratchTextView2 As ScratchTextView
    Private ScratchTextView3 As ScratchTextView
    Private tvList As List
    Private Label1 As Label
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("Layout1")
    tvList.Initialize
    tvList.Add(ScratchTextView1)
    tvList.Add(ScratchTextView2)
    tvList.Add(ScratchTextView3)
    ScratchImageView1.SetLayout(50dip,50dip,150dip,150dip)
    'ScratchTextView1.SetLayout(0,300dip,100%x,50dip)
    ScratchTextView1.Tag = 1000
    ScratchTextView2.Tag = 500
    ScratchTextView3.Tag = 100


    ScratchTextView1.Invalidate
    ScratchTextView2.Invalidate
    ScratchTextView3.Invalidate
  
    Dim bmp As Bitmap
    bmp.Initialize(File.DirAssets,"donmanfred.png")
    Dim d As BitmapDrawable
    d.Initialize(bmp)
    ScratchImageView1.ImageDrawable = d
  
  
    ScratchImageView1.SetBackgroundImage(bmp)
End Sub

Sub Activity_Resume
    'ScratchImageView1.clear

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ScratchImageView1_onRevealed()
    Log($"ScratchImageView1_onRevealed"$)
End Sub
Sub ScratchImageView1_PercentRevealed(percent As Double)
    Log($"ScratchImageView1_PercentRevealed(${percent})"$)
End Sub

Sub ScratchText_PercentRevealed(percent As Double)
    Log($"ScratchImageView1_PercentRevealed(${percent})"$)
End Sub

Sub ScratchText_onRevealed()
    Log($"ScratchText_onRevealed"$)     
    Dim stv As ScratchTextView = Sender
    Dim amount As Int = stv.Tag
    Label1.Text = "$"&amount
End Sub

Sub ScratchText_onScratching(Scratched As Boolean)
    Log($"ScratchText_onScratching"$)
    Dim stv As ScratchTextView = Sender
    For i = 0 To tvList.Size-1
        Dim s As ScratchTextView = tvList.Get(i)
        If s <> stv Then
            s.Visible = False
        End If
    Next
  
End Sub

Here is the Manifest

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
'SetApplicationAttribute(android:theme, "@style/MaterialTheme")
 
Last edited:
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Any error that starts with: Didn't find class "android.support.v4 means that you are using an old library that was based on Android Support Library. You can jetify it to make it work with AndroidX (Tools - Jetifier).

Make sure that the library resides in the additional libraries folder.
Hi

I got this error message which will not allow me to continue. I checked in the map file

#Tue Feb 16 11:04:51 CAT 2021
billscanner.jar=1613384515000
pdfium.jar=1550240928000

But it will not overwrite it. I did make a copy of the file and deleted the original then copied back the copy , still same issue. i also deleted the map file and tried again but the same error messages




 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
It can't access this folder for some reason. You will need to move it to a different folder. This is strange as Documents folder should be accessible.
I moved it to r: Drive and it did not give an error anymore
I have updated my Android SDK
Latest version of B4A

The Only problem in Jetify is not used


Jetify Map file shows all of these which includes the .jar file that this app uses

B4X:
#Fri Jun 25 17:00:20 CAT 2021
cache.jar=1494660108000
billscanner.jar=1613384515000
threading.jar=1340442798645
websocket.jar=1587542978000
scratchview.jar=1466939269094
touchimageview.jar=1338106948000
b4aaccessibilityservices.jar=1582383347411
bitmapextended.jar=1316898198000
slf4j-api-1.7.30.jar=1590385568000
myownlib13.jar=1613581663735
ss_base64convert.jar=1523298420000
pdfium.jar=1550240928000
native-lib-loader-2.3.4.jar=1590385478000
webp4j-0.0.2.jar=1590385184000
clipboard.jar=1295204432000
expressionevaluator.jar=1297159292419

I then ran the program and it gave me this error

Logger connected to: samsung SM-N950F
--------- beginning of main
Copying updated assets files (2)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
--------- beginning of crash
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
at com.cooltechworks.views.ScratchImageView.onSizeChanged(ScratchImageView.java:172)
at android.view.View.sizeChange(View.java:22621)
at android.view.View.setFrame(View.java:22563)
at android.widget.ImageView.setFrame(ImageView.java:1201)
at android.view.View.layout(View.java:22423)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:60)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:508)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:1041)
at android.view.View.layout(View.java:22426)
at android.view.ViewGroup.layout(ViewGroup.java:6584)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3363)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2827)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1873)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8496)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:986)
at android.view.Choreographer.doCallbacks(Choreographer.java:764)
at android.view.Choreographer.doFrame(Choreographer.java:699)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/b4a.example.ScratchView-9nzfHc6ig35yaYEwn42clQ==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example.ScratchView-9nzfHc6ig35yaYEwn42clQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 35 more
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **

The fact is said Failed resolution, I went to the designer and all I did was to tick full screen, save and compile and it WORKED !!!!.
 
Last edited:
Upvote 0
Top