Problem with Java library

flyteach

New Member
Licensed User
Longtime User
Hi! I'm having fun with B4A. But I'm getting an error when I try to use a java library that I created. I know the library works as I've used it from Java previously. I created the B4A project and it works until I try to Dim the class that's in the library. I have created and added the library in accordance with the instructions in the tutorial and have both files (.jar and .xml).
Here's my Globals. Everything works until I Dim Q as StarClusterNPC.

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

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.
Dim lblMission As Label
Dim lblAgility As Label
Dim lblCharisma As Label
Dim lblCoord As Label
Dim lblEndur As Label
Dim lblIncidental As Label
Dim lblIntel As Label
Dim lblObject As Label
Dim lblPerson As Label
Dim lblRelevant As Label
Dim lblStrength As Label
Dim lblWealth As Label
Dim Q As StarClusterNPC
Dim s As String
Dim x As Int
End Sub

Here's some of the code from the java library file. The rest is just some more methods that are defined.
package SCNPC;



import java.util.Random;
import anywheresoftware.b4a.BA.ShortName;
//import anywheresoftware.b4a.BA.Author;
//import anywheresoftware.b4a.BA.Permissions;
//import anywheresoftware.b4a.BA.Version;

@ShortName("StarClusterNPC")

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Jim
*/
public class StarClusterNPC {

public StarClusterNPC() { };

Random dice = new Random();

public int Roll(int d, int n) {
// d is the type of dice to be used
// n is the number of this die to roll
int x = 0;
for (int i = 1; i <= n; i++) {
x += dice.nextInt(d) + 1;
} // end for
return x;
} //end Roll

public String MakeMission() {
int x = 0;
String y = "A";
x = Roll(20,1);
switch (x) {
case 1: y = "Open Religious Conviction"; break;
case 2: y = "Secret Religious Conviction"; break;
case 3: y = "Victim of Vast Political Conspiracy"; break;
case 4: y = "Delusions of Vast Political Conspiracy"; break;
case 5: y = "Quest for Fame and Glory"; break;
case 6: y = "Spying"; break;
case 7: y = "Searching"; break;
case 8: y = "Open Political Mission"; break;
case 9: y = "Secret Political Mission"; break;
case 10: y = "Refugee"; break;
case 11: y = "Memberof Polictical Cabal"; break;
case 12: y = "Delusions of Membership in Political Cabal"; break;
case 13: y = "On Way to Somewhere Else"; break;
case 14: y = "Fleeing Persecution, Real or Imagined"; break;
case 15: y = "Fleeing Law"; break;
case 16: y = "Theft or Criminal Activity"; break;
case 17: y = "Compelled Against Will"; break;
case 18: y = "Madness"; break;
case 19: y = "Prophecy"; break;
case 20: y = "Love"; break;
} // end switch

return y;
} // end MakeMission

I would appreciate any help in figuring out why this is not working.

Thanks!
Jim Ujcik
 

flyteach

New Member
Licensed User
Longtime User
Oh, I forgot.....

to mention that the error/problem I'm getting is that B4A runs fine and send the app to my emulator. However, the emulator fails and Force Closes the app. If I comment out the Dim Q as StarClusterNPC then the app works like it should.

Again, Thanks for any help.

Jim Ujcik
 
Upvote 0

flyteach

New Member
Licensed User
Longtime User
I found the problem. Thanks for the help. I had to set Eclipse to compile as v1.6 rather than using 1.7..
Jim
 
Upvote 0
Top