変更が必要なレイアウトがありました。だから私はそれに線形のレイアウトを追加し、何とかそれはそれにもわずかに関連していないコードをクラッシュした。だからここで病気のいくつかのコードを投稿します。レイアウト内に物を追加するとクラッシュする
ここでは、私のメインファイルとクラッシュが発生する悪い点があります。 保護されたオーバーライドボイドOnCreate関数(バンドルバンドル) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.layoutLogin);
gbtnSignUp = FindViewById<Button>(Resource.Id.btnSignUp);
gbtnSignIn = FindViewById<Button>(Resource.Id.btnSignIn);
gbtnSignUp.Click += gbtnSignUp_Click;
gbtnSignIn.Click += gbtnSignIn_Click; // here is where it crashes
}
今私のレイアウト。私が追加した部分がクラッシュを追加します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:weightSum="100"
android:layout_height="fill_parent">
<ListView
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/ListViewHighlight"
android:id="@+id/companyListView" />
<ProgressBar
android:layout_weight="10"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/ListViewHighlight"
android:id="@+id/progressBar1" />
<LinearLayout// just from this linear layout existing it causes a crash
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:weightSum="100"
android:id="@+id/linearLayout1">
<TextView
android:text="Text"
android:layout_width="0dp"
android:layout_weight="10"
android:layout_height="match_parent"
android:id="@+id/textView1" />
<ImageButton
android:src="@drawable/defaultAdd"
android:layout_width="0dp"
android:layout_weight="90"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:id="@+id/imageButton1" />
</LinearLayout>
</LinearLayout>
このレイアウトは、クラッシュの原因となっているビューにもリンクされていません。私はプロジェクト内からこのビューへの参照をすべて削除してしまっていましたが、それでもクラッシュしました。
私が指定した行で壊すように強制するエラーメッセージがここにあります。
System.NullReferenceException:オブジェクト参照が、まだ、その後、いくつかの処理を行い、ボタンを押すことができ、私は病気のうち、この行コメント、まだitll実行することができるようにすることができますが、また
オブジェクトのインスタンスに設定されていません私はそれを最初に押すことができないはずです非常にbizzareの行動、。ログインボタンの
XML
<Button
android:text="Sign In"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="0dp"
android:id="@+id/btnSignIn"
android:textSize="25sp"
android:background="@drawable/ButtonSignInStyle"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
これで、線形レイアウトを読み込んだ後、コードが通過できるようになりました。私はその線形のレイアウトの中に何かを持っていれば今は壊れます – TheMangaStand