I am trying to port an app to the Android platform, but am new to Android development. I can find plenty of documentation on the Android build environment, but Remobjects/C# (by necessity) is slightly different, and I am burning a tremendous amount of time trying to figure out some minor details which I assume are obvious to someone experienced with Android/Java. What has me stuck right now is the following:
I am subclassing ViewGroup to create a group to do some special formatting for an editor. My class is EditPhrase:
namespace and.cross01 {
public class EditPhrase : ViewGroup {
…
}
}
I have been able to instantiate the view group programmatically, but have been unable to have it created directly from in the main layout XML:
The above XML code gives me a warning from the compiler:
Warning The element ‘LinearLayout’ has invalid child element ‘and.cross01.EditPhrase’. List of possible elements expected: 'Theme, Window, (etc. etc.)… and.cross01 C:\Users\andrew\Documents\Visual Studio 2015\Projects\AND.Cross01\AND.Cross01\res\layout\main.layout-xml 79
I have tried adding and removing the path prefiix, removing removing the namespace declaration, adding EditPhrase as an an activity in the AndroidManifest, and every other variation of naming I can think of. I’m probably missing something blindingly obvious, but cannot seem to figure it out.
My apologies. There was so much other code mixed in that I decided to re-type the code rather than copy and edit it, and missed the public keyword (corrected above). The class is declared as public. It works if I instantiate the group programmatically from within MainActivity, so it must be visible externally. Additionally, if I add it as an activity inside of AndroidManifest.android-xml:
I don’t get any complaints; it must be visible when that xml code is compiled/linked. I’m missing some detail somewhere because I cannot figure out how to get it recognized in main.layout-xml.
Hello, looks like it’s a bug in the schema.
I see the same warning in our existing sample, but sample runs and works fine. Thank you for the report, we’ll fix it, but you can continue skipping the warning.
Well, I tried ignoring it as suggested, but I think the warning reflects a real issue not just a warning bug. When I attempt to run the project, I get the Java error:
An exception of type: java.lang.RuntimeException occurred
Message: {java.lang.RuntimeException: Unable to start activity ComponentInfo{and.cross01/and.cross01.MainActivity}: android.view.InflateException: Binary XML file line #79: Error inflating class and.cross01.EditPhrase}
at ActivityThread.performLaunchActivity()
ActivityThread.handleLaunchActivity()
ActivityThread.access$800()
ActivityThread$H.handleMessage()
Handler.dispatchMessage()
It occurs when executing the
ContentView = R.layout.main;
line in MainActivity.onCreate().
The build environment is Visual Studio release 1915 running on Windows 8.1 (in a Parallels VM on OS X El Capitan).
I have also done a rebuild of the Sugar (stable) library to fix referencing bugs mentioned in
http: //talk.remobjects.com/t/error-when-referencing-sugar/7707
The only UI object which triggers the warning is my subclass EditPhrase - all of the standard Buttons, *Layouts, etc. work - so it looks like a linking or reference naming issue. Are there any behind-the-scenes manipulations of the package name going on? Am I correct in simply using the
namespace and.cross01
to be equivalent to a Java package statement
package and.cross01
in defining the fully qualified path in XML? (and.cross01.EditPhrase)
Is there any way for me to be able to browse the compiled symbol space? That would go a very long way in helping me to diagnose these issues myself.
Thank you fro that. The test case worked. I finally narrowed it down to the presence or absence of a non-void constructor for the ViewGroup subclass. If I have an EditPhrase(Context context) constructor (with or without a call to the base class constructor), I get the runtime exception.
This then leaves me somewhat confused. I can create a null constructor for the subclass
public EditPhrase() {
…
}
The application runs, but the null constructor does not get called on class instantiation.
If I create an override constructor for the one which should be getting called
public EditPhrase(Context context) : base(context) {
…
}
I get a runtime error.
I assume that this being caused by some conflict in the naming system for the combination of a C# codebase and an Android target platform. Is there any way to initialize a ViewGroup (or other UI) subclass? Is there some other special constructor naming system which I can use to initialize my subclasses?