Android Question What is the correct set of Libraries to be used?

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi
I am using Http(1.22), HttpUtils2(2.10), OkHttp(1.00).
I want to have Multipart File upload functionality for which i am adding OkHttpUtils2(2.20)
It is not compiling showing error as below.

Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lanywheresoftware/b4a/samples/httputils2/httpjob;

Also my B4A verision is 5.02(1)
Can you pls guide which library should be removed ?

Thanks
Juzer
 

Juzer Hussain

Active Member
Licensed User
Longtime User
Thanks Erel,
I removed the two but now i am getting following error
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I tried attaching detaching libraries and restarting the app nothing seems to work.
Pls help.
Juzer
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
post the FULL errormessage

I guess you still using old http instead of okhttp libraries.

Upload your project to check
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
I have removed HTTP Library. Full Error is as follows.

java.lang.NoClassDefFoundError: Failed resolution of: Lanywheresoftware/b4a/objects/ServiceHelper$StarterHelper;
at anywheresoftware.b4a.samples.httputils2.httputils2service.onCreate(httputils2service.java:48)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
at android.app.ActivityThread.-wrap4(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
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.ClassNotFoundException: Didn't find class "anywheresoftware.b4a.objects.ServiceHelper$StarterHelper" on path: DexPathList[[zip file "/data/app/com.svps-3/base.apk"],nativeLibraryDirectories=[/data/app/com.svps-3/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)
... 10 more
Suppressed: java.lang.ClassNotFoundException: anywheresoftware.b4a.objects.ServiceHelper$StarterHelper
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)
... 11 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

Thanks
Juzer
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
OkHttpUtils2 library requires a newer version of B4A. You will need to use the source code instead of the compiled library: https://www.b4x.com/android/forum/threads/54723/#content

Hi Erel,
I am struggling with image file upload thru MultipartPost.
As you said i removed okHttputils2 library and added HttpUtils2Service.bas inside HttpUtils2_Scr.zip(as it is not compatible with B4A)
I am using https://www.b4x.com/android/forum/threads/android-http-multipart-requests.8411/ for uploading image file

It gives error on line Dim hc As HttpClient
If i change HttpClient to okHttpClient it will compile is it correct ?
Finally after running it wont upload gives error "ModSecurity Action 501"

Just for info i am using this on ASP side

HttpFileCollection uploadFiles = Request.Files;

// Build HTML listing the files received.
string summary = "<p>Files Uploaded:</p><ol>";

// Loop over the uploaded files and save to disk.
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles;

// Access the uploaded file's content in-memory:
System.IO.Stream inStream = postedFile.InputStream;
byte[] fileData = new byte[postedFile.ContentLength];
inStream.Read(fileData, 0, postedFile.ContentLength);

// Save the posted file in our "data" virtual directory.
postedFile.SaveAs(Server.MapPath("App") + "\\" + postedFile.FileName);

(I am sorry i am not getting "code tags" ??)

Pls help me on this.
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Erel,
I am struggling with image file upload thru MultipartPost.
As you said i removed okHttputils2 library and added HttpUtils2Service.bas inside HttpUtils2_Scr.zip(as it is not compatible with B4A)
I am using https://www.b4x.com/android/forum/threads/android-http-multipart-requests.8411/ for uploading image file

It gives error on line Dim hc As HttpClient
If i change HttpClient to okHttpClient it will compile is it correct ?
Finally after running it wont upload gives error "ModSecurity Action 501"

Just for info i am using this on ASP side

HttpFileCollection uploadFiles = Request.Files;

// Build HTML listing the files received.
string summary = "<p>Files Uploaded:</p><ol>";

// Loop over the uploaded files and save to disk.
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles;

// Access the uploaded file's content in-memory:
System.IO.Stream inStream = postedFile.InputStream;
byte[] fileData = new byte[postedFile.ContentLength];
inStream.Read(fileData, 0, postedFile.ContentLength);

// Save the posted file in our "data" virtual directory.
postedFile.SaveAs(Server.MapPath("App") + "\\" + postedFile.FileName);

(I am sorry i am not getting "code tags" ??)

Pls help me on this.

I have set Permissions on folder also.
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Sorry Erel I do not want to post duplicates
I posted here because As I was not going anywhere on the previous thread,
I revisited the whole code again and thought may be the problem could be here.
 
Upvote 0
Top