NullPointerException in android.app.Activity.onCreate(android/app/Activity.java:874)

| | August 4, 2015

I’m trying to get libGDX 1.6.1 to run on Android via Ruboto. So far, I:

  • Generated a new libGDX app using the app generator
  • Got the desktop app to run (Java)
  • Got the android app to run (Java)
  • Converted the desktop app to run with JRuby
  • Got a basic Ruboto app that runs with gosu-android
  • Converted the Rubuto app to match, as closely as possible, the libGDX Android app setup

I’ve modeled my TestGame (main game) class and the AndroidLauncher class after the Java ones. Here’s how they look:

class TestGame < ApplicationAdapter
  def create
    @batch = SpriteBatch.new
    @img = Texture.new("assets/badlogic.jpg")
  end

  def render
    Gdx.gl.glClearColor(1, 0, 0, 1)
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
    @batch.begin
    @batch.draw(@img, 0, 0)
    @batch.end
  end
end

### boilerplate/launcher code below

class AndroidLauncher < AndroidApplication
  def onCreate(bundle)
    super # <---------- throws here
    config = AndroidApplicationConfiguration.new
    game = TestGame.new
    initialize(game, config)
    self.content_view = initialize_for_view(game, config)
    puts "Content view is #{self.content_view}"
  rescue Exception => e
    puts "Exception starting #{self.class}: #{e} (#{e.class} #{e.message})n#{e.backtrace.join("n")}"
    super
  end
end

Here’s what that looks like from the generated libGDX code:

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new TestGame(), config);
    }
}

The exception stack I’m getting out of Ruboto when I run it on a Genymotion VM (API 16):

D/dalvikvm( 1989): DEX prep '/data/data/com.terrace.template/app_dex/org/jruby/proxy/com/badlogic/gdx/backends/android/AndroidApplication$Proxy0.jar': unzip in 0ms, rewrite 10ms
I/System.out( 1989): Exception starting AndroidLauncher:  (Java::JavaLang::NullPointerException )
I/System.out( 1989): android.app.Activity.onCreate(android/app/Activity.java:874)
I/System.out( 1989): java.lang.reflect.Method.invokeNative(Native Method)
I/System.out( 1989): java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:511)
I/System.out( 1989): RUBY.onCreate(jar:file:/data/app/com.terrace.template-1.apk!/template_activity.rb:35)

What I tried:

  • I checked if my libs directory matches the one from the generated libGDX project. It does.
  • I checked the Activity class docs. They make no mention of throwing this exception.
  • I looked for the Android.app.Activity source, but couldn’t find it online (I assume it’s not available)
  • I checked with the Ruboto devs if my initializtion of my activity is correct. It appears that it is.
  • I checked the value of bundle. As per the docs, it’s nil. (Setting it to a new Bundle instance doesn’t help.)
  • I checked my AndroidManifest.xml. It’s identical to the libGDX generated one.
  • I checked my local.properties file. I have target=android-16, while libGDX uses target=android-19, although I don’t think that matters.

I’m at a loss. I think something’s wrong with my Android app setup, but I don’t know how to troubleshoot it further.

Please ask if you need more information. You can see the current snapshot of my work here. The working JRuby desktop app is here.

Leave a Reply