C# Xamarin Android |无法激活JNI句柄
安卓,谁能告诉我为什么会出现这个错误:C# Xamarin Android |无法激活JNI句柄,c#,android,exception,xamarin,xamarin.android,C#,Android,Exception,Xamarin,Xamarin.android,安卓,谁能告诉我为什么会出现这个错误: System.NotSupportedException: Could not activate JNI Handle 0x5400029 (key_handle 0x4272e7c8) of Java type 'md53e540c9aae5d831a93a27cad628f9744/Timer' as managed type 'Timer.Timer'. 当我尝试为类计时器中的任何按钮分配某个方法时,我得到了它 范例 secondsBtn.Clic
System.NotSupportedException: Could not activate JNI Handle 0x5400029 (key_handle 0x4272e7c8) of Java type 'md53e540c9aae5d831a93a27cad628f9744/Timer' as managed type '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));
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Android.App;
使用Android.Content;
使用Android.Graphics;
使用Android.OS;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.Util;
使用Android.Support.V4.Content;
使用系统线程;
名称空间计时器
{
类计时器:视图
{
私人油漆油漆1=新油漆();
私人油漆油漆2=新油漆();
私人油漆油漆3=新油漆();
私有整数偏移=5;
私有整数timerWidth=15;
专用颜色浅灰色{get;set;}
专用颜色暗灰色{get;set;}
专用颜色蓝色蓝色{get;set;}
专用颜色BGcolor{get;set;}
私有整数秒{get;set;}
私有整数分钟数{get;set;}
私有int Gours{get;set;}
System.Timers.Timer t=新的System.Timers.Timer(1000);
私有整数度froseconds=360/60;
私有文本视图secondsTxtView;
私有文本视图minutesTxtView;
私有文本视图hoursTxtView;
专用按钮备用SBTN;
私人按钮分钟数;
私人按钮小时数;
私有文本视图insideTxtTimeView;
私有文本视图insideTxtTypeView;
公共计时器(上下文):基(上下文)
{
}
公共计时器(上下文,IAttributeSet attrs):基本(上下文,attrs)
{
使无效();
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=findviewbyd(Resource.Id.timer\u txt\u view\u seconds);
minutesTxtView=findviewbyd(Resource.Id.timer\u txt\u view\u minutes);
hoursTxtView=findviewbyd(Resource.Id.timer\u txt\u view\u hours);
secondsBtn=findviewbyd(Resource.Id.timer\u bt\u秒);
minutesBtn=findviewbyd(Resource.Id.timer\u bt\u分钟);
hoursBtn=findviewbyd(Resource.Id.timer\u bt\u hours);
insideTxtTimeView=FindViewById(Resource.Id.timer\u inside\u time\u视图);
insideTxtTypeView=FindViewById(Resource.Id.timer\u inside\u type\u视图);
paint1.Color=DarkGray;
paint1.TextSize=230;
paint2.Color=BGcolor;
颜料3.颜色=蓝蓝色;
t、 已用+=委托
{
秒++;
秒=秒%60;
((活动)上下文).RunOnUiThread(委托{Invalidate();});
};
t、 Start();
}
私有void ClearTxtViews()
{
secondsTxtView.SetTextColor(暗光线);
minutesTxtView.SetTextColor(暗光线);
hoursTxtView.SetTextColor(暗光线);
secondsBtn.SetTextColor(暗光线);
分钟BTN.SetTextColor(暗光线);
小时BTN.SetTextColor(暗光线);
}
受保护的覆盖无效OnDraw(画布)
{
中点=新点(宽度/2,高度/2);
int半径=高度/2-偏移;
底座.OnDraw(帆布);
画布.画圈(宽度/2,高度/2,高度/2-偏移,画图1);
canvas.DrawArc(新的RectF(middle.X-半径,middle.Y-半径,middle.X+半径,middle.Y+半径),-90,DegreesFroSeconds*Seconds,true,paint3);
画布。画圈(宽度/2,高度/2,高度/2-(偏移量+计时器宽度),画图2);
}
公共静态颜色GetColorFromInteger(整型颜色)
{
返回Color.Rgb(Color.GetRedComponent(Color)、Color.GetGreenComponent(Color)、Color.GetBlueComponent(Color));
}
}
}
您在哪里创建您在FindViewById
呼叫中使用的按钮和TextView
s?@SushiHangover谢谢这就是问题所在。我错误地调用了FindViewById…@Sushingover,我正在从xml文件扩展视图,因此我不需要动态创建按钮/文本视图。但我还是犯了这个错误。为什么/@zackraiyan您应该问一个新问题,询问您正在使用的代码和异常输出您在哪里创建您在FindViewById
调用中使用的按钮和TextView
s?@SushiHangover谢谢这就是问题所在。我错误地调用了FindViewById…@Sushingover,我正在从xml文件扩展视图,因此我不需要动态创建按钮/文本视图。但我还是犯了这个错误。为什么/@zackraiyan你应该问一个关于你正在使用的代码和异常输出的新问题