5

Has anyone imported this sliding menu project https://github.com/jfeinstein10/SlidingMenu in their Monodroid application?

I've imported the jar file (com.slidingmenu.lib.slidingmenuactivity.jar) in a new JavaLibraryProject.

I've created a new activity which extends from from SlidingActivity.

My project builds without any errors, but at runtime I get this exception

Java.Lang.NoClassDefFoundError: com.slidingmenu.lib.R$layout 

on

base.OnCreate(bundle)

public class MainActivity : SlidingActivity
{
    public override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);    //The EXCEPTION is thrown here
        SetContentView(Resource.Layout.activity_main);
    }

    public override void SetBehindContentView(int p0)
    {
        base.SetBehindContentView(p0);
    }        
}

Any ideas anyone? Thanks :)

EDIT

Ok. I've done a little modification:

I've added the "assets", "bin" and "res" folders to a ".zip" file which I've added in my AndroidJavaLibrary project.

It compiles fine, but now I get another error on the same line:

Android.Views.InflateException: Binary XML file line #2: Error inflating class com.slidingmenu.lib.SlidingMenu
Mihai
  • 2,740
  • 31
  • 45

2 Answers2

4

You need to include the Jar in both your Java Binding Library and your Mono for Android application. Just add a folder called libs to your Mono for Android project and copy the Jar file into that. You need to then set the build action to AndroidJavaLibrary.

So your solution should look like this:

  • Java Binding Library - The Jar file should be in the JarInputs folder and the build action should be InputJar
  • Mono for Android application project - Jar file should be in your libs folder and the build action set to AndroidJavaLibrary
Alex Wiese
  • 8,142
  • 6
  • 42
  • 71
  • I've done that: copied the jar in the monorail application (but it's in the root of the project). I've also set it as AndroidJavaLibrary. any other ideas ?:) – Mihai Nov 17 '12 at 05:26
  • Have you added the required resource files? eg. slidingmenumain.xml etc. – Alex Wiese Nov 17 '12 at 06:45
  • hmm no. what's that? anyway ... I can't check now, I'llhhave to do it on Monday – Mihai Nov 17 '12 at 07:43
  • It appears there are layouts/drawables etc. that the library depends on. I found them here https://github.com/jfeinstein10/SlidingMenu/tree/master/library/res – Alex Wiese Nov 17 '12 at 07:46
  • Ok. I've done a little modification: I've added the "assets", "bin" and "res" folders to a ".zip" file which I've added in my AndroidJavaLibrary project. It compiles fine, but now I get another error on the same line: Android.Views.InflateException: Binary XML file line #2: Error inflating class com.slidingmenu.lib.SlidingMenu – Mihai Nov 19 '12 at 08:40
  • I'm kind of stuck. Any ideas :) ? – Mihai Nov 20 '12 at 10:55
  • I will try to implement it but I won't get a chance to for a few days – Alex Wiese Nov 21 '12 at 09:16
  • @Mihai Can you share what you have so far somewhere public so we can help debug the issue? – chrisntr Dec 13 '12 at 16:55
  • Here's a link with what I've done so far. I've also added ActionBarSherlock in my project (but that doesn't work either). The main thing I need is the sliding menu, but if you have any ideas on how to integrate ActionBarSherlock, it would be great :). Thanks https://www.dropbox.com/sh/tpxw06sukxcokfw/d6-Cd2ntI0 – Mihai Dec 14 '12 at 08:05
0

I finally got it working

public class Activity1 : SlidingActivity
{
    int count = 1;

    public override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource

        SetContentView(Resource.Layout.Main);
        SetBehindContentView(Resource.Layout.menu);
        // Get our button from the layout resource,
        // and attach an event to it

        Button button = FindViewById<Button>(Resource.Id.MyButton);

        button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
    }
} 

And I updated Monodroid to the latest version 4.4.54

Hope this helps someone :)

Mihai
  • 2,740
  • 31
  • 45
  • I am still curious how you solved the issue with the Binary XML file line #2: Error inflating class com.slidingmenu.lib.SlidingMenu – Brandon Meyer Jun 19 '13 at 20:29
  • This is the project which I reference in Visual Studio. Hope it helps https://www.dropbox.com/s/wcbdocn9hgd1zqf/SlidingMenuJava%20-%20Old.rar – Mihai Jun 20 '13 at 07:24