Java Question newbie raisevent error

markcasio

Member
Licensed User
Longtime User
newbie raiseEvent error

Hi,
I was following the examples of building my own lib. for b4a.
But when i tried to add a raiseEvent i got stuck. Here is what i did...

package anywheresoftware.b4a.sample;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("Firslib")
@Version(1.00f)
@Events(values={"myevent(test as int)" })
public class Firtlib {
private BA ba;
public int multiply(int x) {
ba.raiseEvent(this, "eventname"+"_myevent", 208);
return x * 2;
}

}

When i call this lib from b4a i receive java.lang.NullpointerException.:confused:

Thank you,
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Hi,
I was following the examples of building my own lib. for b4a.
But when i tried to add a raiseEvent i got stuck. Here is what i did...

package anywheresoftware.b4a.sample;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("Firslib")
@Version(1.00f)
@Events(values={"myevent(test as int)" })
public class Firtlib {
private BA ba;
public int multiply(int x) {
ba.raiseEvent(this, "eventname"+"_myevent", 208);
return x * 2;
}

}

When i call this lib from b4a i receive java.lang.NullpointerException.:confused:

Thank you,

The last parameter of raiseEvent should be an Array of Objects.

B4X:
ba.raiseEvent(this, "eventname"+"_myevent", new Object[]{208});

That should properly call your B4A Sub named "eventname_myevent" with the Int value 208.

BUT you have not defined the instance of BA named ba.
Each time your B4A code calls a library method an instance of the BA object is passed to that method.

So a simplified version of your class could be:

B4X:
public class Firtlib {
   public int multiply(BA ba, int x) {
      ba.raiseEvent(Firtlib.this, "eventname"+"_myevent", new Object[]{208});
      return x * 2;
   }
}

Martin.
 
Top