Java Question Crash at Dim

Damdu98

Member
Licensed User
Longtime User
Hello Forum Users,

I tried to imitate Erels Example Lib "FirstLib" from the Tutorial, but when I run the Application, I get the message "The Application MyFTP (Process de.Dominik.MyFTPTest) has stopped unexpectly".

My B4A-Code:
B4X:
'Activity module
Sub Process_Globals
   Dim fl As FirstLib
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Log(fl.calculate(2, 5))
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

My Java-Code:
B4X:
package de.Dominik.FirstLib;

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

@ShortName("FirstLib")
@Version(1f)

public class FirstLib {
   /**
    * Multiplicates the first given Parameter with the second
    * @param a: The first multiplication factor
    * @param b: The second multiplication factor
    * @return: The product of both factors
    */
   public int calculate(int a, int b)
   {
      return a*b;
   }   
}

I'm sure you can help me.
Thanks a lot
 

Gigatron

Member
Licensed User
Longtime User
Hi i make the same project under eclipse

Import android 8 SDK

Here the source:
B4X:
package com.gtr.firstlib;


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

@ShortName("FirstLib")
@Version(1f)

public class Firstlibrary {

   
   

    
      /**
       * Multiplicates the first given Parameter with the second
       * @param a: The first multiplication factor
       * @param b: The second multiplication factor
       * @return: The product of both factors
       */
      public int calculate(int a, int b)
      {
         return a*b;
      }   
   }

After this i ve tested ON B4A ..

With Log(fl.calculate(2,5))... The logcat show 10 .. result..
It's working without problem...

After finish writing code on eclipse:
1 select Firstlib on project explorer
2 Right click and select Export
3 Select jarfile and select Firstlib if not selected
4 Write destination folder on jarfile.... like this H:\Program Files\Anywhere Software\Basic4android\New-Libs\Firstlib.jar
5 select next and next again + finish.
6 Creat xml docfile ... explained at the video..
7 Launch B4A
8 Right Click on right, Referenced Library and REFRESH..
9 Select the new library Firstlib... when it's loaded on your project, you can use it.

I dont know the other way...
 
Last edited:

Damdu98

Member
Licensed User
Longtime User
Thanks for your quick reply Gigatron.
I tried it like you said, but nevertheless the application crashes like in my first post.

I I did this way:
1. I created a Java Project named FirstLibrary
2. I added the three librarys to the build path
3. I created a class named FirstLibrary
4. I pasted your code
5. I created the jar-file like you said
6. I created the xml-file like in the video
 
Last edited:

Damdu98

Member
Licensed User
Longtime User
In the LogCat messages it seems like the Android-System can not find my package. I think thats the problem:confused:... I'm sure I'm doing something wrong :sign0085:
In the attachments are my eclipse project exported as Archive-File, the *.xml and the *.jar that I've created and the unfiltered LogCat.

I have no idea how to solve my problem...
 

Attachments

  • LogCat.txt
    3.2 KB · Views: 281
  • FirstLib.zip
    2.2 KB · Views: 271
  • FirstLibCreated.zip
    1.8 KB · Views: 257

stevel05

Expert
Licensed User
Longtime User
Did you copy the jar and xml to whichever directory you have set as the additional libraries folder in the ide? (Tools/Configure Paths)
 

Damdu98

Member
Licensed User
Longtime User
Yes, I have set the additional libraries folder.
It's: "H:\_Programmieren\Android\0_Librarys"

I always copy the *.jar-file and the *.xml-file to this folder, but nevertheless it didn't work...
 

Damdu98

Member
Licensed User
Longtime User
Are you sure that the right jar / xml are referenced? Try changing the version of the library and then do a refresh in the libs folder. Make sure that the version gets updated.

Thanks Erel, but I have already done this and it works. I changed the Version of the library from 1.1 to 1.2 and after I refreshed the libraries tab the library had the version number 1.20
 

Damdu98

Member
Licensed User
Longtime User
I believe that the problem happens because you are compiling with Java 7 instead of 6.

I used Java SDK 7 in eclipse, you're right Erel. I changed to Java 6_29, but it still crashes.
I attached a screenshot of my eclipse Package Explorer and all my referenced librarys, but I think I've referenced the right ones...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are still compiling with Java 7.
You can use the javap tool to find the java version. Major version should be 50.
B4X:
c:\Program Files (x86)\Java\jdk1.6.0_21\bin>javap -verbose -classpath c:\users\h\desktop de.Dominik.Test.FirstLibrary
Compiled from "FirstLibrary.java"
public class de.Dominik.Test.FirstLibrary extends java.lang.Object
  SourceFile: "FirstLibrary.java"
  RuntimeVisibleAnnotations: length = 0x14
   00 02 00 16 00 01 00 17 73 00 18 00 19 00 01 00
   17 46 00 1A
  minor version: 0
  major version: 51
 

Damdu98

Member
Licensed User
Longtime User
You are still compiling with Java 7.
You can use the javap tool to find the java version. Major version should be 50.
Thanks a lot Erel, but how can I change the Javaversion that I'm compiling with?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Configure build path - Libraries:
SS-2011-11-21_17.47.35.png


Remove java 7 and add java 6 jre.
 

Damdu98

Member
Licensed User
Longtime User
Thanks a lot for your quick answer Erel!! I changed the Library to Java 6 and now it works without problems!! :sign0060:
 
Top