Android Question Program Won't run in emulator

MrKim

Well-Known Member
Licensed User
Longtime User
I am having difficulty running my app in the emulator although it runs fine on my device.

The following code did not run at all but failed completely and stopped the debugger until I created and emulator at API level 18 Google APIs, then it at least failed gracefully. The line that failed:

B4X:
Dim MyFile As PublicFile

The error message for the above line:
B4X:
Error occurred on line: 41 (trialexp)
java.lang.ClassNotFoundException: com.datasteam.b4a$system$file$PublicFile
    at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:544)
    at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:516)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:320)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
    at android.view.View.performClick(View.java:4240)
    at android.view.View$PerformClick.run(View.java:17721)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)

The above error message is in debug mode. If I compile for release the error changes to:
B4X:
java.lang.NoSuchFieldError: android.os.Environment.DIRECTORY_DOCUMENTS
    at com.datasteam.b4a.system.file.PublicFile.<clinit>(PublicFile.java:22)
    at com.superlativesoftware.nagtrial.trialexp._buybtn_click(trialexp.java:319)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
    at android.view.View.performClick(View.java:4240)
    at android.view.View$PerformClick.run(View.java:17721)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
And the program stops.

B4A version 3.80 Android SDK Manager Version 22.2.1.

And again, this code runs fine on My Samsung Note 2 Android 4.4.2 but I would like to test for other versions.
This is a new version of a program that has been running fine for over a year and which continues to run fine on the emulator. The code that is failing is all new. The PublicFile Type and the .Length property were not used in the older version of the program.

Thanks for any help.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
The DIRECTORY_DOCUMENTS is only available on 4.x and above, lower SDKs will display an error.
It is failing with that error at 4.3. At 4.2.2 and below it doesn't even fail gracefully, it blows completely out of the debugger, but I did not realize that was a 4.x and above and I would like to use earlier versions. Is there an alternative to the PublicFile Lib that works with 2.2 and above? I need to read and write to the public directories.

Thanks
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Movies: File.Combine(File.DirRootExternal, "Movies")
Pictures: File.Combine(File.DirRootExternal, "Pictures")
Downloads: File.Combine(File.DirRootExternal, "Download") 'not downloads
DCIM: File.Combine(File.DirRootExternal, "DCIM")
Erel, thank you. Do you have an answer for why .length does not work as well? Perhaps I should start a new thread for that one. I thought these were both going to be emulator issues.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Please upload a project that demonstrates the length issue.
Turns out that was not the issue. It was another version related issue that I was able to resolve.

Sorry to have bothered you.
 
Upvote 0
Top