2016-10-02 53 views
-1

所以我想更改一个布局。所以我给它添加了一个线性布局,并以某种方式崩溃了与它无关的代码。所以我在这里发布一些代码。在布局中添加事物会导致崩溃

这是我的主要文件和发生崩溃的病态点。 保护覆盖无效的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 
    } 

现在我的布局。 Ill指出我添加哪个部分会增加崩溃。

<?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使其能够运行,但不适依然能够按下按钮,然后做一些非常棒的行为,我不应该按它开始。

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" /> 
+0

在阅读代码让它通过的线性布局后,现在没有了。现在,如果我在线性布局 – TheMangaStand

回答

0

其实这个问题是一些乱七八糟的时候我为了它移动到其他文件夹导出我的程序所发生的情况。我将我的文件复制并粘贴到旧版本的原始文件夹中,并且完美运行。因此,如果有人以不太好的方式移动文件,可能会导致无法预料的问题,而这些问题不会像这样。

1

您的布局不包含与IDS btnSignUpbtnSignIn按钮。您需要添加它们或删除活动代码中的4行。

缺少布局

<Button 
    android:id="@+id/btnSignUp" 
    .../> 

<Button 
    android:id="@+id/btnSignIn" 
    .../> 
+0

内有东西,但它们确实有问题,就会中断。我将为其中一个按钮添加代码 – TheMangaStand

+0

然后请询问下次提供所有信息的完整问题-.- –