Xamarin Android |无法激活JNI句柄

时间:2016-09-10 08:17:48

标签: c# android exception xamarin xamarin.android

Android,有人可以告诉我为什么会收到此错误:

System.NotSupportedException: Could not activate JNI Handle 0x5400029 (key_handle 0x4272e7c8) of Java type 'md53e540c9aae5d831a93a27cad628f9744/Timer' as managed type 'Timer.Timer'.

当我尝试将一些方法分配给我的类Timer

中的任何按钮时,我得到了它

实施例

secondsBtn.Click+=delegate{

};

当我将它添加到构造函数时,它会抛出错误

这是我的班级

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Android.App;
    using Android.Content;
    using Android.Graphics;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.Util;
    using Android.Support.V4.Content;
    using System.Threading;

    namespace Timer
    {


        class Timer : View
        {
            private Paint paint1 = new Paint();
            private Paint paint2 = new Paint();
            private Paint paint3 = new Paint();

            private int offset = 5;
            private int timerWidth = 15;

            private Color LightGray { get; set; }
            private Color DarkGray { get; set; }
            private Color AzureBlue { get; set; }
            private Color BGcolor { get; set; }

            private int Seconds { get; set; }
            private int Minutes { get; set; }
            private int Gours { get; set; }
            System.Timers.Timer t = new System.Timers.Timer(1000);
            private int DegreesFroSeconds = 360 / 60;

            private TextView secondsTxtView;
            private TextView minutesTxtView;
            private TextView hoursTxtView;


            private Button secondsBtn;
            private Button minutesBtn;
            private Button hoursBtn;

            private TextView insideTxtTimeView;
            private TextView insideTxtTypeView;



            public Timer(Context context) : base(context)
            {
            }

            public Timer(Context context, IAttributeSet attrs) : base(context, attrs)
            {
                Invalidate();
                LightGray = GetColorFromInteger(ContextCompat.GetColor(context, Resource.Color.light_gray));
                DarkGray = GetColorFromInteger(ContextCompat.GetColor(context, Resource.Color.dark_gray));
                AzureBlue = GetColorFromInteger(ContextCompat.GetColor(context, Resource.Color.azure_blue));
                BGcolor = GetColorFromInteger(ContextCompat.GetColor(context, Resource.Color.bg_color));


                secondsTxtView = FindViewById<TextView>(Resource.Id.timer_txt_view_seconds);
                minutesTxtView = FindViewById<TextView>(Resource.Id.timer_txt_view_minutes);
                hoursTxtView = FindViewById<TextView>(Resource.Id.timer_txt_view_hours);

                secondsBtn = FindViewById<Button>(Resource.Id.timer_bt_seconds);
                minutesBtn = FindViewById<Button>(Resource.Id.timer_bt_minutes);
                hoursBtn = FindViewById<Button>(Resource.Id.timer_bt_hours);

                insideTxtTimeView = FindViewById<TextView>(Resource.Id.timer_inside_time_view);
                insideTxtTypeView = FindViewById<TextView>(Resource.Id.timer_inside_type_view);




                paint1.Color = DarkGray;
                paint1.TextSize = 230;

                paint2.Color = BGcolor;
                paint3.Color = AzureBlue;


                t.Elapsed += delegate
                {
                    Seconds++;
                    Seconds = Seconds % 60;
                    ((Activity)Context).RunOnUiThread(delegate { Invalidate(); });
                };
                t.Start();


            }


            private void ClearTxtViews()
            {
                secondsTxtView.SetTextColor(DarkGray);
                minutesTxtView.SetTextColor(DarkGray);
                hoursTxtView.SetTextColor(DarkGray);

                secondsBtn.SetTextColor(DarkGray);
                minutesBtn.SetTextColor(DarkGray);
                hoursBtn.SetTextColor(DarkGray);
            }

            protected override void OnDraw(Canvas canvas)
            {

                Point middle = new Point(Width / 2, Height / 2);
                int radius = Height / 2 - offset;
                base.OnDraw(canvas);
                canvas.DrawCircle(Width / 2, Height / 2, Height / 2 - offset, paint1);
                canvas.DrawArc(new RectF(middle.X - radius, middle.Y - radius, middle.X + radius, middle.Y + radius), -90, DegreesFroSeconds * Seconds, true, paint3);
                canvas.DrawCircle(Width / 2, Height / 2, Height / 2 - (offset + timerWidth), paint2);
            }
            public static Color GetColorFromInteger(int color)
            {
                return Color.Rgb(Color.GetRedComponent(color), Color.GetGreenComponent(color), Color.GetBlueComponent(color));
            }
        }
    }

0 个答案:

没有答案
相关问题