Java Question Create lib in Eclipse error

DonManfred

Expert
Licensed User
Longtime User
do you have maybe simple-medium eclipse source codes that you are willing to share?
the best way for me to learn is to see a full code (that works :) )
I can imagine. Same here ;-)
I´ll zip some projects - i released in the past weeks - for you later when i´m at home...
 

Informatix

Expert
Licensed User
Longtime User
hi

i am trying to create a very simple lib in eclipse but i am getting an error while i try to build my app in b4a.

this is the code in the java class:

B4X:
package sagital.net.geo;

import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("geometry")
@Version(value = 1)

public class geometry{

    /*
     * Calculate Cube Surface by his x,y,z
     */
    public double CubeGetSurface(double x, double y, double z) {
        return (((x * y) * 2) + ((x * z) * 2) + ((y * z) * 2));
    }
  
    /*
     * Calculate Cube Volume by his x,y,z
     */
    public double CubeGetVolume(double x, double y, double z) {
        return x*y*z;
    }
  
    /*
     * Calculate Circle Area by his radius
     */
    public double CircleGetArea(double r) {
        return Math.PI * Math.pow(r, 2);
    }
  
    /*
     * Calculate Sphere Surface Area by his radius
     */
    public double SphereGetSurfaceArea(double r) {
        return 4 * Math.PI * Math.pow(r, 2);
    }
  
    /*
     * Calculate Sphere Volume by his radius
     */
    public double SphereGetVolume(double r) {
        return (double) 4/3 * Math.PI * Math.pow(r, 3);
    }
  
    /*
     * Calculate Square Area by his x,y
     */
    public double SquareGetArea(double x, double y) {
          return (x * y);
    }
}

this is the error i get when i compile:



i have followed the tutorial and did everything like in the video so i guess something in my code is wrong??

thank you
Use Java 7, not Java 8, and I'm pretty sure that will compile fine.
 

ilan

Expert
Licensed User
Longtime User
My libraries compiled with Java 7 work fine with B4A v7+. It does not seem that Java 8 is mandatory.

thank you i will try.
i need to mention that the lib works with B4J without any problems (using Java 8+ for compile). maybe something with my b4a is wrong. but i will anyway try your suggestion.

thanx :)

btw i have started to learn java and i like its freedom. one thing i really liked it that you can create 2 methods with the same name but with different arguments.

this could be very handy in b4a.

like:

log(<string>)
log(<string>,<color>)

instead of using different call methods you use the same and just add another argument and java knows when you mean the second method. cool :)
 

ilan

Expert
Licensed User
Longtime User
I just tried with B4A v7.30. The library compiled with Java 8 prevents B4A from compiling (parse error... 52.0). The same code compiled with Java 7 does not produce any issue.
Please note that B4A is set with the path to Java 8.

hmmm... ok thank you for this info so i will compile my libs with java 7 and not java 8 in the future. thanx
 

ilan

Expert
Licensed User
Longtime User
I just tried with B4A v7.30. The library compiled with Java 8 prevents B4A from compiling (parse error... 52.0). The same code compiled with Java 7 does not produce any issue.
Please note that B4A is set with the path to Java 8.

ok i have tried it but i am getting the same ...52 error.

when you say compile with Java 7 u mean to choose the JRE source:

java7.jpg

or choose the jdk version?

java2.jpg
 

Informatix

Expert
Licensed User
Longtime User
ok i have tried it but i am getting the same ...52 error.

when you say compile with Java 7 u mean to choose the JRE source:

View attachment 59214

or choose the jdk version?

View attachment 59213
None of them. In the package explorer on the left, click with the right button on your project and select Build Path > Configure Build Path. Change the Java version here.
 

ilan

Expert
Licensed User
Longtime User
None of them. In the package explorer on the left, click with the right button on your project and select Build Path > Configure Build Path. Change the Java version here.

thank you that worked.
i also tried to compile with b4a SimpleCompiler tool without changing to java 7 and it also worked.

so using b4a simple compiler works with Java 8
otherwise changing to java 7 works with eclipse directly

thank you very much for all your help @Informatix and @DonManfred :)
 

LucaMs

Expert
Licensed User
Longtime User
i know how to create classes that returns objects and use methods and simple stuff like for(){} loops and do while, if statements and Switch.
how to convert variables and use them so real basics. the main thing here is to learn the syntax.
Syntax?

What are byte and Byte?
What Boxing, Unboxing, Autoboxing?
Overloads?
Static methods?
Inheritance-Polymorphism-Abstract classes? Nested classes?Anonymous classes? Interfaces?
Generics?
...
...

Syntax! :D
 

ilan

Expert
Licensed User
Longtime User
Syntax?

What are byte and Byte?
What Boxing, Unboxing, Autoboxing?
Overloads?
Static methods?
Inheritance-Polymorphism-Abstract classes? Nested classes?Anonymous classes? Interfaces?
Generics?
...
...

Syntax! :D

no

for example:
B4A:

B4X:
    Dim LucaMSappCount, bankaccount As Int
    Dim FerrariInGarage, poor, finallyrich, BicicleInGarage As Boolean
   
    If LucaMSappCount > 182 Then
        FerrariInGarage = True
    Else
        BicicleInGarage = True
    End If
   
    For i = 0 To LucaMSappCount-1
        bankaccount = bankaccount + 1
    Next
   
    Dim isBigger As Boolean = LucaMSappCount > 182
   
    Select isBigger
        Case True
            finallyrich = True   
        Case False
            poor = True   
    End Select

now Java:

B4X:
public class lucaclass {
       
    public static void main (String args[]) {
       
        int LucaMSappCount = 182, bankaccount = 0;
        boolean FerrariInGarage = false, poor = false, finallyrich = false, BicicleInGarage = false;
       
        if (LucaMSappCount > 182) {
            FerrariInGarage = true;
        }else {
            BicicleInGarage = true;
        }
       
       
        for (int i=0; i<LucaMSappCount; i++) {
            bankaccount+=1;
        }
               
    }

}

ok the last example (Select Case) was not added because it seems that java does not support boolean in a switch statement
so any java expert is welcome to give a simple solution :)
 

LucaMs

Expert
Licensed User
Longtime User
I meant to say that thinking that the main difference is the syntax is really wrong. The syntax is the minimum!

Anyway...

B4X:
    If LucaMSappCount > 182 Then
        FerrariInGarage = True
    Else If LucaMSappCount > 20
        BicicleInGarage = True
    Else
        LucaMShasToWalk = True
    End If
 

ilan

Expert
Licensed User
Longtime User
I meant to say that thinking that the main difference is the syntax is really wrong. The syntax is the minimum!

Anyway...

B4X:
    If LucaMSappCount > 182 Then
        FerrariInGarage = True
    Else If LucaMSappCount > 20
        BicicleInGarage = True
    Else
        LucaMShasToWalk = True
    End If

i want it in a Switch statement not If. i know its not only the syntax. i know that i am a very beginner and i know that i want to know more :)

but you cannot climb the hill from the top, right?

so i start with writing code in java and the start with those things you wrote above.

i have also tried android studio and its really complex. lots of possibilities but i think its better for android dev then eclipse.
i want also to learn swift so my next month will be dedicated for Java and Swift.

i am not planning to leave b4x. i still like to code with it its much simpler but if you know native you have more control about your b4x projects.
like using native objects...
 
Top