Java 所以I';我试图替换SupportFragment,但它在onCreateView部件上崩溃
每当我切换出布局时,Fragment就会使它脱离onCreateView,这让我相信问题出在xml文件本身Java 所以I';我试图替换SupportFragment,但它在onCreateView部件上崩溃,java,android,Java,Android,每当我切换出布局时,Fragment就会使它脱离onCreateView,这让我相信问题出在xml文件本身 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation = "vertical" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pa
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation = "vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textColor="#FFFFFF"
android:background="@color/lining"
android:text="Añadir actividad"
android:textStyle="bold"/>
<view
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginBottom="10dp"
android:background="@color/lining" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Nombre de actividad"
android:textAlignment="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="@+id/activity_name"/>
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/lining" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Prioridad"
android:textAlignment="center"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="20dp"
android:id="@+id/priority"/>
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/lining" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Añadir fecha"
android:id="@+id/date_select"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fecha"
android:textSize="20dp"
android:text="--/--/----"
android:textAlignment="center"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
出现错误java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”
我已经无数次地修改了java和xml代码,但我似乎找不到这一问题的根本原因,更重要的是,字符串.equals似乎是最大的罪魁祸首,所以我根本不明白会发生什么
谁能帮我一把吗?我是个新手,这一点还没有弄清楚^^ 这是一个简单的打字错误。因为您正在使用以下xml:
<view> .... </>
。。。。
这是不正确的,因为它不是以大写字母开头的。正确的答案是:
<View> .... </>
。。。。
logcat消息后面应该是导致异常的文件,并填写行号。它通常是在异常堆栈跟踪之后找到的第一个蓝色链接。如果仍然找不到完整的堆栈跟踪,请发布它。@user1504495位于com.example.omega.taskcon.fragments.AddFragment.onCreateView(AddFragment.java:57)@user1504495我发现如果删除这些视图,效果会很好。。。wtf?我回家后会试试,看看你的答案是否有效,但这很奇怪,预览版似乎承认小写字母很好……你是对的,预览版根本没有抱怨。但它会给您带来运行时错误。因为同样的错误,我浪费了很多时间。
<view> .... </>
<View> .... </>