This is not a wrapper for the JAMA project but nevertheless a JAR and XML that I have created with Simple Library Compiler (SLC) so that JAMA can be used within a B4A project by making use of inline Java Code. The inline Java code (called via B4A library

I have compiled Jama-1.0.3 into a B4A compatible library (with SLC) so that it can be used with inline Java Code. You therefore need B4A version >= 4.30.

I attach the following:

The JAR and XML created with SLC (B4ALibraryFiles.zip). Copy them to your additional library folder.

The Java Code that was compiled to create the JAR and XML

A screenshot of how I have set up SLC (you need to browse to the folder that holds the src folder)

The B4A project that uses and demonstrates the compiled library and how to use it with inline Java code.

Some sample code:

I will assist where I can for whoever wants to add the remaining methods in Matrix.java to this B4A project should you need some assistance. But if you follow the B4A code, the inline Java code, and the code in Matrix.java then you should have no problem to add the remaining methods.

Enjoy!

**JavaObject**) interfaces with the JAR that was created. I have not added B4A code and inline Java code to make use of all the methods. Only most of the constructors and some methods. The purpose of this exercise was to get the interface to work. It should now be simple to add the remaining methods in Matrix.java (see the attached Java code) to make use of all of the methods in Matrix.java. You can add the remainder of the methods in Matrix.java in the same way as what I have added some of the other methods. It is not difficult - fairly simple to do.I have compiled Jama-1.0.3 into a B4A compatible library (with SLC) so that it can be used with inline Java Code. You therefore need B4A version >= 4.30.

I attach the following:

The JAR and XML created with SLC (B4ALibraryFiles.zip). Copy them to your additional library folder.

The Java Code that was compiled to create the JAR and XML

A screenshot of how I have set up SLC (you need to browse to the folder that holds the src folder)

The B4A project that uses and demonstrates the compiled library and how to use it with inline Java code.

Some sample code:

B4X:

```
#Region Project Attributes
#ApplicationLabel: JHSJAMA
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#AdditionalJar:JHSJAMA
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the a
Dim jo As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
jo.InitializeContext
'***********************************************************************************************
jo.RunMethod("initialize2", Array(4,4,3.0))
jo.RunMethod("times", Array(4.0))
'*************************************************************************************************
Dim c(5,4) As Double
Log(" ")
For i = 0 To 4
For j = 0 To 3
c(i,j) = Rnd(0,100)
Log(c(i,j))
Next
Next
Log(" ")
jo.RunMethod("initialize3", Array(c))
'*************************************************************************************************
Dim d(5,4) As Double
Log(" ")
For i = 0 To 4
For j = 0 To 3
d(i,j) = Rnd(0,100)
Log(d(i,j))
Next
Next
Log(" ")
jo.RunMethod("initialize4", Array(d, 3, 2))
'*************************************************************************************************
Dim e(20) As Double
Log(" ")
For i = 0 To 19
e(i) = Rnd(0,100)
Log(e(i))
Next
Log(" ")
jo.RunMethod("initialize5", Array(e,5))
Dim a(3,3) As Double
Log(" ")
a = jo.RunMethod("identity", Array(3,3))
For i = 0 To 2
For j= 0 To 2
Log(a(i,j))
Next
Next
'************************************************************************************************
Dim b(4,3) As Double
Log(" ")
b = jo.RunMethod("random", Array(4,3))
For i = 0 To 3
For j= 0 To 2
Log(b(i,j))
Next
Next
'************************************************************************************************
Dim f(4,3) As Double
Log(" ")
For i = 0 To 3
For j = 0 To 2
f(i,j) = Rnd(0,100)
Log(f(i,j))
Next
Next
Log(" ")
jo.RunMethod("initialize3", Array(f))
Log(" ")
Dim clmn() As Double
clmn = jo.RunMethod("getColumnPackedCopy", Null)
For i = 0 To 11
Log(clmn(i))
Next
Log(" ")
Dim rw() As Double
rw = jo.RunMethod("getRowPackedCopy", Null)
For i = 0 To 11
Log(rw(i))
Next
Log(" ")
Log(jo.RunMethod("getRowDimension", Null))
Log(jo.RunMethod("getColumnDimension", Null))
'************************************************************************************************
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If Java
//this import needs to be here to call the methods in the Matrix class
import Jama.Matrix;
Matrix mm = null;
/** Construct an m-by-n matrix of zeros.
@param m Number of rows.
@param n Number of colums.
*/
public void initialize1 (int m, int n) {
mm = new Matrix(m,n);
}
//*********************************************************************************************
/** Construct an m-by-n constant matrix.
@param m Number of rows.
@param n Number of colums.
@param s Fill the matrix with this scalar value.
*/
public void initialize2 (int m, int n, double s) {
mm = new Matrix(m,n,s);
}
//*********************************************************************************************
/** Construct a matrix from a 2-D array.
@param A Two-dimensional array of doubles.
@exception IllegalArgumentException All rows must have the same length
@see #constructWithCopy
*/
public void initialize3 (double[][] A) {
mm = new Matrix(A);
double[][] C = mm.getArray();
for (int i = 0; i < C.length; i++) {
for (int j = 0; j < C[0].length; j++) {
BA.Log("" + C[i][j]);
}
}
}
//*********************************************************************************************
/** Construct a matrix quickly without checking arguments.
@param A Two-dimensional array of doubles.
@param m Number of rows.
@param n Number of colums.
*/
public void initialize4 (double[][] A, int m, int n) {
mm = new Matrix(A, m, n);
double[][] C = mm.getArray();
for (int i = 0; i < C.length; i++) {
for (int j = 0; j < C[0].length; j++) {
BA.Log("" + C[i][j]);
}
}
}
//*********************************************************************************************
/** Construct a matrix from a one-dimensional packed array
@param vals One-dimensional array of doubles, packed by columns (ala Fortran).
@param m Number of rows.
@exception IllegalArgumentException Array length must be a multiple of m.
*/
public void initialize5 (double vals[], int m) {
mm = new Matrix(vals,m);
double[][] C = mm.getArray();
for (int i = 0; i < C.length; i++) {
for (int j = 0; j < C[0].length; j++) {
BA.Log("" + C[i][j]);
}
}
}
//*********************************************************************************************
/** Multiply a matrix by a scalar, C = s*A
@param s scalar
@return s*A
*/
public void times(double paramDouble){
mm = mm.times(paramDouble);
double[][] C = mm.getArray();
BA.Log("" + C[0][0]);
}
//*********************************************************************************************
/** Generate identity matrix
@param m Number of rows.
@param n Number of colums.
@return An m-by-n matrix with ones on the diagonal and zeros elsewhere.
*/
public double[][] identity (int m, int n) {
Matrix a;
a = mm.identity(m,n);
double[][] C = a.getArray();
return C;
}
//*********************************************************************************************
/** Generate matrix with random elements
@param m Number of rows.
@param n Number of colums.
@return An m-by-n matrix with uniformly distributed random elements.
*/
public double[][] random (int m, int n) {
Matrix a;
a = mm.random(m,n);
double[][] C = a.getArray();
return C;
}
//*********************************************************************************************
/** Make a one-dimensional column packed copy of the internal array.
@return Matrix elements packed in a one-dimensional array by columns.
*/
public double[] getColumnPackedCopy () {
double[] a;
a = mm.getColumnPackedCopy();
return a;
}
//*********************************************************************************************
/** Make a one-dimensional row packed copy of the internal array.
@return Matrix elements packed in a one-dimensional array by rows.
*/
public double[] getRowPackedCopy () {
double[] a;
a = mm.getRowPackedCopy();
return a;
}
//*********************************************************************************************
/** Get row dimension.
@return m, the number of rows.
*/
public int getRowDimension () {
return mm.getRowDimension ();
}
//*********************************************************************************************
/** Get column dimension.
@return n, the number of columns.
*/
public int getColumnDimension () {
return mm.getColumnDimension ();
}
#End If
```

I will assist where I can for whoever wants to add the remaining methods in Matrix.java to this B4A project should you need some assistance. But if you follow the B4A code, the inline Java code, and the code in Matrix.java then you should have no problem to add the remaining methods.

Enjoy!

#### Attachments

Last edited: