C# 无法转换类型为';Android.Widget.Button';
我遇到了一个奇怪的异常,它在android上运行了一年 当我这样做时:C# 无法转换类型为';Android.Widget.Button';,c#,android,xamarin,xamarin.android,C#,Android,Xamarin,Xamarin.android,我遇到了一个奇怪的异常,它在android上运行了一年 当我这样做时: TimerButton btnOut = FindViewById<TimerButton>(Resource.Id.btnTimer); 这只是一个简短的例子,因为我使用这个按钮和一个定制的事件处理程序,所以我可以在大约x秒内完成一些事情。不重要。 所以我去掉了一些代码,比如SetState 请注意,这项工作持续了1年左右 我尝试的是: 项目->清洁 清理项目的Bin和Obj文件夹 重新创建XML布局
TimerButton btnOut = FindViewById<TimerButton>(Resource.Id.btnTimer);
这只是一个简短的例子,因为我使用这个按钮和一个定制的事件处理程序,所以我可以在大约x秒内完成一些事情。不重要。
所以我去掉了一些代码,比如SetState
请注意,这项工作持续了1年左右
我尝试的是:
- 项目->清洁
- 清理项目的Bin和Obj文件夹
- 重新创建XML布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:minWidth="25px"
android:minHeight="25px">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Status"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:id="@+id/txtStatus" />
<Button
android:text="Timer Button"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@drawable/ButtonState"
android:shadowColor="#C4BEBE"
android:layout_gravity="center"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:layout_marginTop="10.1dp"
android:layout_marginBottom="10.1dp"
android:id="@+id/btnTimer" />
</LinearLayout>
</ScrollView>
</LinearLayout>
将布局中的
按钮更改为{此处为您的包名。
比如:
示例XAML:
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.sushihangover.custombutton.XAMLButton
android:id="@+id/customButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
将布局中的按钮
更改为{your package name here}。时间按钮
比如:
示例XAML:
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.sushihangover.custombutton.XAMLButton
android:id="@+id/customButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
您的b计数器
是一个按钮
而不是时间按钮
。将
替换为
。将MyProject
替换为TimerButton
类的命名空间。您的btnTimer
是一个按钮
而不是TimerButton
。将
替换为
。用TimerButton
类的名称空间替换MyProject
。在xml中检查“btnTimer”是否未声明为“Button”。它应该是Java.Lang.Exception:二进制XML文件行#1:错误膨胀类TimerButton检查android包名。我应该检查的是ZoetermeerAPP???@StefanvandeLaarschot也发布XML。检查XML中的“btnTimer”是否未声明为“Button”。它应该是Java.Lang.Exception:Binary XML文件行#1:Error Expling class TimerButton检查android软件包名称。我应该检查的是ZoetermeerAPP???@StefanvandeLaarschot post your XML Alway.android.Views.InflateException:Binary XML文件行#1:Error Expling class com.myproject.mycompany.TimerButton我正在使用Xamarin它是否需要成为我的命名空间?不起作用已经试过了这是namespace@StefanvandeLaarschot我更新了我的答案,我假设您没有注册Java类名,因为Java不了解C#名称空间。否则,Xamarin将自动生成FQ类名:即:md522d0961607fa9d72a190d1511c1fa557.XAMLButton
.Android.Views.InflateException:Binary-XML文件行#1:错误膨胀类com.myproject.mycompany.timerbuttoni在Xamarin中工作是否需要作为我的命名空间?不起作用已经试过了这是namespace@StefanvandeLaarschot我更新了我的答案,我假设您没有注册Java类名,因为Java不了解C#名称空间。否则,Xamarin将自动生成FQ类名:即:md522d0961607fa9d72a190d1511c1fa557.XAMLButton
.Android.Views.InflateException:Binary-XML文件行#1:错误膨胀类com.myproject.mycompany.timerbuttoni在Xamarin中工作是否需要作为我的命名空间?已经不工作了。它的名称空间。打字错误。使用名称空间后会出现什么错误?Thnx它是名称空间非常有用:)ty very muchAndroid.Views.InflateException:二进制XML文件行#1:在Xamarin中工作的类com.myproject.mycompany.TimerButtonIm膨胀时出错它需要是我的名称空间吗?已经不工作了。它的名称空间。打字错误。使用名称空间后会出现什么错误??Thnx是名称空间非常有用:)ty非常有用
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.sushihangover.custombutton.XAMLButton
android:id="@+id/customButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
[Register("com.sushihangover.custombutton.XAMLButton")]
public class XAMLButton : Button