gpt4 book ai didi

java - 在 Android 中加载屏幕时出错

转载 作者:行者123 更新时间:2023-12-02 00:02:05 27 4
gpt4 key购买 nike

当我尝试加载屏幕时出现错误。它有一个相对布局,里面有一个表布局。该错误与屏幕膨胀有关,因此我认为这在某种程度上是相关的。

我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#777777"
android:orientation="horizontal" >

<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="Choose"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtTitle"
android:layout_marginLeft="80dp"
android:layout_marginTop="50dp"
android:background="#000000" >
<TableRow
android:id="@+id/Header1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/txtProblema"
android:layout_margin="2dp"
android:gravity="center"
android:background="#FFF000"
android:textColor="#000000"
android:text="Problema"
android:layout_span="2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="30dp" />

<TextView
android:id="@+id/txtAbreviatura"
android:layout_margin="2dp"
android:gravity="center"
android:background="#FFF000"
android:textColor="#000000"
android:text="Abreviatura"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkWorms"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtWorms"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Gusano"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtGU"
android:layout_margin="2dp"
android:gravity="center"
android:text="GU"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkCSBAdult"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSBAdult"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="CSB-Adulto"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSBA"
android:layout_margin="2dp"
android:gravity="center"
android:text="CSB-A"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkCSBLarva"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSBLarva"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="CSB-Larva"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSBL"
android:layout_margin="2dp"
android:gravity="center"
android:text="CSB-L"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkCSFLarva"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSFLarva"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="CSF-Larva"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtCSFL"
android:layout_margin="2dp"
android:gravity="center"
android:text="CSF-L"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkAves"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtAves"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Aves"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtAve"
android:layout_margin="2dp"
android:gravity="center"
android:text="Ave"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkThrips"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtThrips"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Thrips"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtTH"
android:layout_margin="2dp"
android:gravity="center"
android:text="TH"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkHongo"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtHongo"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Hongo"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtHG"
android:layout_margin="2dp"
android:gravity="center"
android:text="HG"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkBacteria"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtBacteria"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Bacteria/Pudrición"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtBac"
android:layout_margin="2dp"
android:gravity="center"
android:text="Bac"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkKernelPopping"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtKernelPopping"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="Kernel Popping"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtKP"
android:layout_margin="2dp"
android:gravity="center"
android:text="KP"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>

<TableRow
android:id="@+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/chkNoKernel"
android:layout_margin="2dp"
android:background="#FFFFFF"
android:textSize="30dp" />

<TextView
android:id="@+id/txtNoKernel"
android:layout_margin="2dp"
android:background="@string/table_bg_color"
android:gravity="center"
android:text="No Kernel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF0000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtNK"
android:layout_margin="2dp"
android:gravity="center"
android:text="NK"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@string/abrv_bg_color"
android:textSize="30dp" />
</TableRow>
</TableLayout>

<Spinner
android:id="@+id/spnNoKernel"
android:layout_width="500dp"
android:layout_height="80dp"
android:layout_alignLeft="@+id/tableLayout1"
android:layout_below="@+id/tableLayout1"
android:layout_marginTop="30dp" />

<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:onClick="SaveKernelInspection"
android:text="Save" />
</RelativeLayout>

还有我的 list ,以防万一

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.domedroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="16" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.domedroid.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.example.domedroid.DomeScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.PotholderScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.PlantScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.DataSelectionScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.InspectionScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.KDCScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>

<activity
android:name="com.example.domedroid.KernelInspectionScreen"
android:parentActivityName="com.example.domedroid.MainActivity"
android:screenOrientation="portrait" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.domedroid.MainActivity" />
</activity>
</application>
</manifest>

除了通常的 OnCreate 和 onCreateOptionsMenu 之外,没有其他代码用于这些屏幕。当然,setContentView 设置为该屏幕。错误是这样的:

02-01 13:20:22.314: E/AndroidRuntime(6494): FATAL EXCEPTION: main
02-01 13:20:22.314: E/AndroidRuntime(6494): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.domedroid/com.example.domedroid.KernelInspectionScreen}: android.view.InflateException: Binary XML file line #64: Error inflating class <unknown>
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.os.Looper.loop(Looper.java:137)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-01 13:20:22.314: E/AndroidRuntime(6494): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 13:20:22.314: E/AndroidRuntime(6494): at java.lang.reflect.Method.invoke(Method.java:511)
02-01 13:20:22.314: E/AndroidRuntime(6494): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-01 13:20:22.314: E/AndroidRuntime(6494): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-01 13:20:22.314: E/AndroidRuntime(6494): at dalvik.system.NativeStart.main(Native Method)
02-01 13:20:22.314: E/AndroidRuntime(6494): Caused by: android.view.InflateException: Binary XML file line #64: Error inflating class <unknown>
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
02-01 13:20:22.314: E/AndroidRuntime(6494): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-01 13:20:22.314: E/AndroidRuntime(6494): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.Activity.setContentView(Activity.java:1881)
02-01 13:20:22.314: E/AndroidRuntime(6494): at com.example.domedroid.KernelInspectionScreen.onCreate(KernelInspectionScreen.java:10)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.Activity.performCreate(Activity.java:5104)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-01 13:20:22.314: E/AndroidRuntime(6494): ... 11 more
02-01 13:20:22.314: E/AndroidRuntime(6494): Caused by: java.lang.reflect.InvocationTargetException
02-01 13:20:22.314: E/AndroidRuntime(6494): at java.lang.reflect.Constructor.constructNative(Native Method)
02-01 13:20:22.314: E/AndroidRuntime(6494): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-01 13:20:22.314: E/AndroidRuntime(6494): ... 26 more
02-01 13:20:22.314: E/AndroidRuntime(6494): Caused by: android.content.res.Resources$NotFoundException: File #0f6f0f from drawable resource ID #0x7f040002
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.content.res.Resources.loadDrawable(Resources.java:1970)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.view.View.<init>(View.java:3328)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.widget.TextView.<init>(TextView.java:454)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.widget.TextView.<init>(TextView.java:449)
02-01 13:20:22.314: E/AndroidRuntime(6494): ... 29 more
02-01 13:20:22.314: E/AndroidRuntime(6494): Caused by: java.io.FileNotFoundException: #0f6f0f
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.content.res.AssetManager.openNonAssetNative(Native Method)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.content.res.AssetManager.openNonAsset(AssetManager.java:407)
02-01 13:20:22.314: E/AndroidRuntime(6494): at android.content.res.Resources.loadDrawable(Resources.java:1962)
02-01 13:20:22.314: E/AndroidRuntime(6494): ... 33 more

感谢您的帮助!

编辑:我正在添加该类的代码。就像我说的,它没有太多重要的代码,但也许你们可以看到一些我看不到的东西。

package com.example.domedroid;

import android.os.Bundle;
import android.view.Menu;

public class KernelInspectionScreen extends MainActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kernel_inspection_screen);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

最佳答案

我认为问题来自于你使用字符串作为背景

android:background="@string/table_bg_color"

它应该是一个颜色对象。

关于java - 在 Android 中加载屏幕时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651734/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com