Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have my java source code exported into a .jar file in eclipse. I have created a java binding library in Xamarin and added the .jar file into the jars folder. I have further referenced the library project into my Xamarin android project.

This is the code for my activity:-
C#
public class HorizontalActivity : Activity
    {

        private FVControl fView;
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.Main);

            Title = Resource.String.activity_title.ToString ();

            fView = new FViewControl(this, FVControl.Horizontal);

            fView.Adapter = (Android.Widget.IAdapter)new TravelAdapter (this);   //Error here

            SetContentView (fView);
        }



I get the error:-



[MonoDroid] UNHANDLED EXCEPTION: System.InvalidCastException: Cannot cast from source type to destination type.
[MonoDroid] at FJarLibraryTest.HorizontalActivity.OnCreate (Android.OS.Bundle) <0x0010f>
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x00048>
[MonoDroid] at (wrapper dynamic-method) object.be54cf5e-5a7f-424b-a1e2-a76991021bdd (intptr,intptr,intptr) <0x0001f>
[mono] 
[mono] Unhandled Exception:
[mono] System.InvalidCastException: Cannot cast from source type to destination type.
[mono]   at FJarLibraryTest.HorizontalActivity.OnCreate (Android.OS.Bundle bundle) [0x00000] in <filename unknown>:0 
[mono]   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00000] in <filename unknown>:0 
[mono]   at (wrapper dynamic-method) object:be54cf5e-5a7f-424b-a1e2-a76991021bdd (intptr,intptr,intptr)
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Cannot cast from source type to destination type.
[mono-rt]   at FJarLibraryTest.HorizontalActivity.OnCreate (Android.OS.Bundle bundle) [0x00000] in <filename unknown>:0 
[mono-rt]   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00000] in <filename unknown>:0 
[mono-rt]   at (wrapper dynamic-method) object:be54cf5e-5a7f-424b-a1e2-a76991021bdd (intptr,intptr,intptr)
Posted
Comments
Maarten Kools 19-Dec-13 3:58am    
Looks pretty straightforward, the TravelAdapter class does not implement the IAdapter interface. If you post some code of the TravelAdapter class then we can tell for sure, but based on the given information, I'd say it doesn't implement the interface.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900