0

I say fake because the method isn't declared as abstract, but it doesn't have an implementation.

I'm trying to fix a bug introduced by using BridJ. BridJ uses a custom annotation to annotate a method inside of an Android Activity. The method has the following signature:

@Library("example")
public static void helloLog(Pointer<Byte> logThis);

But the compiler complains of Missing method body, or declare abstract on these two lines of code. So I decided to look at the source code for the annotation, which is:

@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR})
public @interface Library {

    /**
     * Name of this library.
     */
    String value();

    /**
     * Names of libraries that need to be loaded before this library is loaded
     */
    String[] dependencies() default {};

    String versionPattern() default "";
}

After reading up on Java Custom Annotations, I don't see anything wrong with the definition of the annotation. For the heck of it, I added an implementation to the helloLog() method.

public static void helloLog(Pointer<Byte> logThis) {}

After which the error goes away. I didn't expect it to fix the problem, but FWIW, it allows me to build and run, but it crashes on startup because of a NullPointerException that I plan on looking into.

Update 1

@thomas-kläger and others suggested adding the native keyword to helloLog. I tried that, but then I get this runtime error:

java.lang.UnsatisfiedLinkError: No implementation found for void connectedsolutions.cummins.com.bridjtest.MainActivity.helloLog(org.bridj.Pointer) (tried Java_connectedsolutions_cummins_com_bridjtest_MainActivity_helloLog and Java_connectedsolutions_cummins_com_bridjtest_MainActivity_helloLog__Lorg_bridj_Pointer_2)

I will read up on the documentation and examples some more. Thanks.

Martin
  • 748
  • 7
  • 20
  • 2
    Java does not allow non-abstract methods to have an empty body. – CollinD Dec 09 '16 at 22:03
  • 2
    ...except if they are native methods: `public static native void helloLog(Pointer logThis);` – Thomas Kläger Dec 09 '16 at 22:09
  • ...or if the annotation is processed at compile time to add an empty body. – Joe C Dec 09 '16 at 22:18
  • It sounds like that method should have the modifier `native` on it. Adding an empty body seems like it would preclude BridJ from knowing that anything needs to be done with that method during its compile-time code generation. – Lucas Ross Dec 09 '16 at 22:23
  • Thanks all. The `native` keyword makes sense, but then it complains about a ` No implementation found for...` error. I will update the post with more details and keep reading up on the BridJ documentation and examples. – Martin Dec 12 '16 at 15:06
  • 1
    ...except that this is not a `native` method. – Adam Arold Dec 12 '16 at 15:11

0 Answers0