Forum: JRuby Access a Ruby class from Java reflection

4bfcb18ca5298df54d8eb410244d004f?d=identicon&s=25 Uwe Kubosch (donv)
on 2013-10-05 18:11
(Received via mailing list)
Hi all!

This is for the Ruboto project, but may be helpful for other platforms
as well.

I am trying to access a Ruby subclass of a Java class
(android.app.Fragment) from an Android XML file.  I assume that when the
XML is parsed, it uses Java reflection to access the Ruby class.

The tutorial for using fragments is here:
https://github.com/ruboto/ruboto/wiki/Tutorial:-fragments

When we try to start the app, we get an exception:

I/System.out(13941): Exception creating activity: Binary XML file line
#3: Error inflating class fragment
I/System.out(13941):
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
I/System.out(13941):
android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
I/System.out(13941):
android.view.LayoutInflater.inflate(LayoutInflater.java:489)
I/System.out(13941):
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
I/System.out(13941):
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
I/System.out(13941):
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
I/System.out(13941):
android.app.Activity.setContentView(Activity.java:1835)

The full stack trace is here:  https://gist.github.com/donv/6842581

We think the problem is that the Java class for the Ruby class is not
found.

We could of course create the fragments programmatically and set up the
layout programmatically, but we would like to investigate using XML for
layout.

The fragment class, TitlesFragment, is converted using
TitlesFragment.become_java!, and we try to access it with the name
RubyTitlesFragment or ruby.TitlesFragment.  Is this the right way to do
it?

--
Uwe Kubosch
uwe@kubosch.no
http://kubosch.no/
This topic is locked and can not be replied to.