当前位置: 首页 > 知识库问答 >
问题:

我在学习android studio时遇到了这个错误

颜祖鹤
2023-03-14

我在学习android studio时遇到了这个错误:

08-20 11:56:52.192 981 5-9815/com.example.android.courtcountee1 E/AndroidRuntime:致命异常:main process:com.example.android.android.courtcountee1,PID:9815 java.lang.runtimeException:无法启动活动ComponentInfo{com.example.android.courtcountee1.mainactivity}:Android.view.fillateException:二进制XML文件行#66:试图在Android.app.activitythread.performLaunch的空activity(activityThread.java:3319),android.app.activityThread.handlelaunchactivity(activityThread.java:3415),android.app.activityThread.access)在com.android.inter在com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)处的nal.os.zygoteinit.java:1120)处的nal.os.zygoteinit.java:1230(zygoteinit.java:1230),原因是:android.view.fillateException:二进制XML文件行#66:试图在:380)在Android.support.v7.app.appcompatdelegateimplv9.setContentView(appcompatdelegateimplv9.java:287)在Android.support.v7.app.app.compatactivity.setContentView(appcompatactivity.java:139)在com.example.android.courtcountee1.mainactivity.oncreate(mainactivity.java:15)在Android.app.activity.performCreate(activity.java:6904):3266)在Android.app.acTivityThread.HandleLaunchActivity(ActivityThread.java:3415) 在Android.app.activitythread.access$1100(activitythread.java:229) 在Android.app.activitythread$h.handleMessage(activitythread.java:1821) 在Android.os.handler.DispatchMessage(Handler.java:102) 在Android.os.looper.loop(looper.java:148) 在Android.app.activitythread.main(activitythread.java:7325) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:1120) 由:java.lang.nullPointerException引起:试图在Android.view.layoutInflater.createViewFromTag(layoutInflater.java:750),Android.view.layoutInflater.java:716),Android.view.layoutInflater.rflateChildren(layoutInflater.java:847),Android.view.layoutInflater.rflateChildren(Android.view.layoutinflater.rflateChildren(layoutinflater.java:810)在Android.view.layoutinflater.ablavate(layoutinflater.java:527)在Android.view.layoutinflater.ablavate(layoutinflater.java:429) 在Android.view.layoutinflater.inflate(Layoutinflater.java:380) 在Android.support.v7.app.AppCompatDelegateImplv9.SetContentView(AppCompatDelegateImplv9.java:287) 在Android.support.v7.app.appcompatactivity.SetContentView(appcompatactivity.java:139) 在com.example.android.courtCountee1.mainActivity.onCreate(mainActivity.java:15) 在Android.app.activity.performCreate(activity.java:6904) 在Android.app.instrumentation.callActivityonCreate(instrumentation.java:1136) 在Android.app.activitythread.performLaunchActivity(activitythread.java:3266) 在Android.app.activitythread.HandleLaunchActivity(activitythread.java:3415) 在Android.app.activitythread.access$1100(activitythread.java:229) 在Android.app.activitythread$h.handleMessage(activitythread.java:1821) 在Android.os.handler.DispatchMessage(Handler.java:102) 在Android.os.looper.loop(looper.java:148) 在Android.app.activitythread.main(activitythread.java:7325) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:1120) 

XML

我认为视图标记导致了这个问题,因为删除它解决了这个问题

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="24dp"
            android:layout_weight="1"
            android:orientation="vertical"
            tools:context="com.example.android.courtcounter.MainActivity">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team A" />

            <TextView
                android:id="@+id/team_a_score"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="24dp"
                android:fontFamily="sans-serif-light"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textColor="#000000"
                android:textSize="56dp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="threePoints"
                android:text="+3 POINTS" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="twoPoints"
                android:text="+2 POINTS" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="freeThrow"
                android:text="Free Throw" />
        </LinearLayout>

        <!--<view
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:background="@android:color/darker_gray">
        </view>-->

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginRight="24dp"
            android:layout_weight="1"
            android:orientation="vertical"
            tools:context=".MainActivity">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team B"
                android:textColor="#616161"
                android:textSize="14sp" />

            <TextView
                android:id="@+id/team_b_score"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="24dp"
                android:fontFamily="sans-serif-light"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textColor="#000000"
                android:textSize="56dp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="threePointsB"
                android:text="+3 POINTS" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="twoPointsB"
                android:text="+2 POINTS" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:onClick="freeThrowB"
                android:text="Free Throw" />
        </LinearLayout>

    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="32dp"
        android:onClick="reset"
        android:text="RESET" />
</RelativeLayout>

共有1个答案

权玉泽
2023-03-14

视图标记必须以大写字母开头,如下所示:

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="24dp"
    android:layout_marginRight="24dp"
    android:background="@android:color/darker_gray">
</View>
 类似资料: