Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Could not activate JNI Handle

mohammadomidvarmohammadomidvar USMember ✭✭
edited July 2017 in Xamarin.Android

Hi!
I want to customize viewpager to make it work vertically. But when setting contentview app cannot create an instance of it and give this error:

System.NotSupportedException: Could not activate JNI Handle 0xeab00029 (key_handle 0x41357db0) of Java type 'md5b3f8461ca967df4f0978d2e01bf012d6/VViewPager' as managed type 'App3.Widgets.VViewPager'.

The custom viewpager:

namespace App3.Widgets
{
    public class VViewPager : ViewPager
    {
        public VViewPager(Context c) : base(c) { Initialize(); }
        public VViewPager(Context c, Android.Util.IAttributeSet attrs) : base(c, attrs) { Initialize(); }
        public VViewPager(IntPtr jr, JniHandleOwnership transfer) : base(jr, transfer) { Initialize(); }

        private void Initialize()
        {
            SetPageTransformer(true, new VerticalPageTransformer());

            OverScrollMode = OverScrollMode.Never;
        }

        private MotionEvent SwapXandY(MotionEvent ev)
        {
            ev.SetLocation(ev.GetY() / Height * Width, ev.GetX() / Width * Height);
            return ev;
        }

        public override bool OnInterceptTouchEvent(MotionEvent ev) => base.OnInterceptTouchEvent(SwapXandY(ev));

        public override bool OnTouchEvent(MotionEvent ev) => base.OnTouchEvent(SwapXandY(ev));

        private class VerticalPageTransformer : IPageTransformer
        {
            //some codes for changing behavior
        }

    }
}

Best Answer

Answers

  • mohammadomidvarmohammadomidvar USMember ✭✭
    Accepted Answer

    Answer is provided here : http://stackoverflow.com/a/10603714/748199
    Any method that modifies View before it is created can cause this, in my case: Initialize()

  • nivekkocnivekkoc IEMember

    Hi, Im having the same issue,
    What did you have to do to rectify this?
    Where did you call initialise?
    Thanks

  • mohammadomidvarmohammadomidvar USMember ✭✭

    Hi!
    I made Initialize() public and I call it in my activity or anywhere that view is found or created.

  • nivekkocnivekkoc IEMember

    Thanks you are a gent!!
    Just one other thing did you manage to get the verticalviewpager
    to slide when swipe up and down rather than left and right?

  • nivekkocnivekkoc IEMember

    Actually i found it, thanks
    I never added SwapXandY(ev)

  • MahdibabaMahdibaba Member
    edited April 15

    1.Install-Package SQLite-Net-PCL
    2.in properties of project go to android manifest tab and give read-external-storage and write-external-storage.
    3.in constructor of connection class write this code.

        private string dbpath = "";
        private string dbName = "YourDB";
        SQLiteConnection db;
        public FriendManagMent()
        {
            dbpath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    

    db=new SQLiteConnection(Path.Combine(dbpath,dbName));

            db.CreateTable<Friend>();     
        }  
    
Sign In or Register to comment.