Android Question File not found

buras3

Active Member
Licensed User
Longtime User
Hey

I get
java.io.FileNotFoundException:
at android.content.res.AssetManager.openAsset(Native Method)


in livewallpaper app before activity create
and only when i connect in log tab .

it's only happens after i restart my device


Please help
 

ilan

Expert
Licensed User
Longtime User
Hey

I get
java.io.FileNotFoundException:
at android.content.res.AssetManager.openAsset(Native Method)


in livewallpaper app before activity create
and only when i connect in log tab .

it's only happens after i restart my device


Please help

can you upload a simple project where it can be reproduced?
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
B4X:
LogCat connected to: 53daf3c1
--------- beginning of system


--------- beginning of crash


--------- beginning of main


** Service (wallpaperservice) Create **


java.io.FileNotFoundException:


    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:331)
    at android.content.res.AssetManager.open(AssetManager.java:305)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:498)
    at michael.sunmoon.wallpaperservice._service_create(wallpaperservice.java:1262)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at michael.sunmoon.wallpaperservice.onCreate(wallpaperservice.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2911)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
java.lang.RuntimeException: Unable to create service michael.sunmoon.wallpaperservice: java.lang.RuntimeException: java.io.FileNotFoundException:
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2921)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException:
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:201)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at michael.sunmoon.wallpaperservice.onCreate(wallpaperservice.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2911)
    ... 8 more
Caused by: java.io.FileNotFoundException:
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:331)
    at android.content.res.AssetManager.open(AssetManager.java:305)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:498)
    at michael.sunmoon.wallpaperservice._service_create(wallpaperservice.java:1262)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    ... 11 more
** Service (wallpaperservice) Create **
java.io.FileNotFoundException:
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:331)
    at android.content.res.AssetManager.open(AssetManager.java:305)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:498)
    at michael.sunmoon.wallpaperservice._service_create(wallpaperservice.java:1262)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at michael.sunmoon.wallpaperservice.onCreate(wallpaperservice.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2911)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446)
    at android.os.Handler.dispatchMessage(Handler.java:102)


    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
java.lang.RuntimeException: Unable to create service michael.sunmoon.wallpaperservice: java.lang.RuntimeException: java.io.FileNotFoundException:
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2921)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException:
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:201)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at michael.sunmoon.wallpaperservice.onCreate(wallpaperservice.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2911)
    ... 8 more
Caused by: java.io.FileNotFoundException:
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:331)
    at android.content.res.AssetManager.open(AssetManager.java:305)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:498)
    at michael.sunmoon.wallpaperservice._service_create(wallpaperservice.java:1262)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    ... 11 more
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (wallpaperservice) Create **
** Service (wallpaperservice) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (wallpaperservice) Create **
** Service (wallpaperservice) Start **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
** Service (wallpaperservice) Create **
** Service (wallpaperservice) Start **
** Activity (main) Pause, UserClosed = true **
** Service (wallpaperservice) Start **
** Service (wallpaperservice) Create **
** Service (wallpaperservice) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (wallpaperservice) Destroy **
** Service (wallpaperservice) Create **
** Service (wallpaperservice) Start **
** Activity (main) Pause, UserClosed = true **
** Service (wallpaperservice) Create **


LocationManager has been initialized.
** Service (wallpaperservice) Start **
** Activity (main) Create, isFirst = true **
(Main, 48) Object was already initialized. (warning #1003)
** Activity (main) Resume **
** Service (wallpaperservice) Destroy **
** Service (wallpaperservice) Create **
LocationManager has been initialized.
** Service (wallpaperservice) Start **
** Activity (main) Pause, UserClosed = true **
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@ffc9fc6 is not valid; is your activity running?
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:86)
    at android.app.Dialog.show(Dialog.java:319)
    at anywheresoftware.b4a.debug.Debug.wait(Debug.java:211)
    at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:260)
    at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:232)
    at michael.sunmoon.wallpaperservice._lwm_sizechanged(wallpaperservice.java:952)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at anywheresoftware.b4a.objects.WallpaperInternalService$LWManager.raiseEvent(WallpaperInternalService.java:99)
    at anywheresoftware.b4a.objects.WallpaperInternalService$B4AEngine.onSurfaceChanged(WallpaperInternalService.java:292)
    at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:768)
    at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:876)
    at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:1163)
    at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
java.lang.RuntimeException: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@ffc9fc6 is not valid; is your activity running?
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:201)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at anywheresoftware.b4a.objects.WallpaperInternalService$LWManager.raiseEvent(WallpaperInternalService.java:99)
    at anywheresoftware.b4a.objects.WallpaperInternalService$B4AEngine.onSurfaceChanged(WallpaperInternalService.java:292)
    at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:768)
    at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:876)
    at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:1163)
    at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5461)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@ffc9fc6 is not valid; is your activity running?
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:86)
    at android.app.Dialog.show(Dialog.java:319)
    at anywheresoftware.b4a.debug.Debug.wait(Debug.java:211)
    at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:260)
    at anywheresoftware.b4a.debug.Debug.ErrorCaught(Debug.java:145)
    at michael.sunmoon.wallpaperservice._lwm_sizechanged(wallpaperservice.java:958)


    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    ... 13 more
** Service (wallpaperservice) Create **
LocationManager has been initialized.
** Service (wallpaperservice) Start **
** Service (wallpaperservice) Create **
LocationManager has been initialized.
** Service (wallpaperservice) Start **
** Service (wallpaperservice) Create **
LocationManager has been initialized.
** Service (wallpaperservice) Start **
** Activity (main) Create, isFirst = true **
(Main, 48) Object was already initialized. (warning #1003)
** Activity (main) Resume **
** Service (wallpaperservice) Destroy **
** Service (wallpaperservice) Create **
LocationManager has been initialized.
** Service (wallpaperservice) Start **
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
hi buras3, i just tried you example.
i installed it on my galaxy s8 and it runs well without any errors. so i restarted my device and i am connected to the ide via USB and i get the Error FILENOTFOUND

so i took a look at the service create sub and i see why you have that error

B4X:
Sub Service_Create
Main.sql1.Initialize(File.DirDefaultExternal,"SunMoon.db",True)
EarthImg.Initialize(File.DirAssets,EarthImgName)
EarthFace=Funcs.GetSettings("Vall","EarthFace")
If EarthFace="South" Then
    ClockImg.Initialize(File.DirAssets,"ClockSouth.png")   
    EarthImgName="NaturalSouth2.png"
Else
    ClockImg.Initialize(File.DirAssets,"ClockNorth.png")
    EarthImgName="NaturalNorth2.png"
End If

EarthImgName is a string and you set the string AFTER you intialize the bitmap EarthImg

so when the device restarts and you try to initialize bitmap EarthImg with the string EarthImgName its not possible since EarthImgName is empty!!!

you need to set the filename and then initialize the bitmap!

so moving the line of the bitmap initialize solved the error.

B4X:
Sub Service_Create
Main.sql1.Initialize(File.DirDefaultExternal,"SunMoon.db",True)
EarthFace=Funcs.GetSettings("Vall","EarthFace")
If EarthFace="South" Then 'FIRST WE SET THE BITMAP FILE NAME TO THE STRING
    ClockImg.Initialize(File.DirAssets,"ClockSouth.png")   
    EarthImgName="NaturalSouth2.png"
Else
    ClockImg.Initialize(File.DirAssets,"ClockNorth.png")
    EarthImgName="NaturalNorth2.png"
End If
EarthImg.Initialize(File.DirAssets,EarthImgName) 'NOW WE CAN INITIALIZE THE BITMAP

btw your bitmaps are huge!! consider to resize them. there is no need to have 1.5-2mb bitmaps and make the app so big (in my opinion)

:)
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
Hey Ilan
Thank you
I made the changes . now there is no error about file not found :)


I did use smaller imgs but then the resolution was not good as big imgs
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Hey Ilan
Thank you
I made the changes . now there is no error about file not found :)

I did use smaller imgs but then the resolution was not good as big imgs

what SOFT are u using?

try GIMP or PS to resize your Images and also don't use CUBIC Interpolation.

try those images i have resized and tell me if the quality is better (it's the half size of your original images)

https://www.dropbox.com/s/jai9vfqay9pz2v0/Files.zip?dl=0
 
Upvote 0
Top