tags:

views:

36

answers:

1

I'm trying to use the Point class from android.graphics, but it appears that all the methods are stubs. For example, the line

Point p = new Point(1, 1);

causes java.lang.RuntimeException: Stub!. If I look at the bytecode for Point, I see a bunch of stubbed methods, e.g:

  // Method descriptor #17 (II)V
  // Stack: 3, Locals: 3
  public Point(int x, int y);
     0  aload_0 [this]
     1  invokespecial java.lang.Object() [1]
     4  new java.lang.RuntimeException [2]
     7  dup
     8  ldc <String "Stub!"> [3]
    10  invokespecial java.lang.RuntimeException(java.lang.String) [4]
    13  athrow
      Line numbers:
        [pc: 0, line: 5]
      Local variable table:
        [pc: 0, pc: 14] local: this index: 0 type: android.graphics.Point
        [pc: 0, pc: 14] local: x index: 1 type: int
        [pc: 0, pc: 14] local: y index: 2 type: int

What's the deal here? Surely they didn't ship a class that's 100% stubs.

+2  A: 

I am guessing that you are looking at android.jar. That JAR file is mostly stubs. The real implementation is on the device.

For a properly configured Android project, running in an emulator or on a device, the constructor for android.graphics.Point and everything else will use the real implementation. You only use android.jar as a compilation target, and it should not be included in the resulting APK file.

CommonsWare
I see. I was trying to test a class using Point from a console app, which apparently isn't possible.
Odrade
@Odrade: yeah, you're not going to be able to use `android.jar` for testing outside of Android. You can always grab the source code for some of the classes and put them in your own JAR, but inter-class dependencies and native methods will probably cause problems for you. Sorry!
CommonsWare