我在Xamarin / Android下的FindViewbyId出现此错误: 错误CS0120属性,方法或非静态字段'需要对象引用。 这是我的axml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutDeadReckoning"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/startx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff66ff66"
android:padding="20px"
android:text="startx"
/>
</LinearLayout>
这是我的代码
public class DeadReckoningActivity : Activity
{//Declaration
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.activity_dead_reckoning);
int method = Intent.GetIntExtra(KEY_RECKONING_METHOD, METHOD_DEAD_RECKONING);
mDeadReckoning = new DeadReckoning(this); //Class
intent = new Intent(this, typeof( BroadcastService) ); // public class BroadcastService : Service
}
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
private class broadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
updateUI(intent);
}
private void updateUI(Intent intent)
{
float mstartx = mDeadReckoning.getmStartX();
TextView startx =FindViewById<TextView>(Resource.Id.startx);
startx.SetText(Convert.ToChar(mstartx));
}
}
}
你能看出出了什么问题吗?