2013-02-01 85 views
0

當我嘗試加載屏幕時,會出現錯誤。它有一個相對佈局,裏面有一個表格佈局。錯誤是關於屏幕膨脹,所以我認爲這是相關的。在Android中加載屏幕時出錯

我的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> 

而我的清單,以防萬一

<?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; 
    } 
} 
+0

Eclipse有時會落後於生成資源ID。如果您使用Eclipse,請嘗試清理項目並重建。 – Krylez

+0

感謝您的回答。不幸的是,它沒有奏效。 – plasmy

+0

@plasmy與您在'KernelInspectionScreen.java'活動中使用的佈局文件相同嗎? –

回答

2

我認爲問題都來自於您使用String作爲背景的事實

的android:背景= 「@字符串/ table_bg_color」

這應該是一個顏色對象。

+0

是的,先生,這正是問題所在。我將字符串中的所有顏色都更改爲顏色對象,並且工作得很好。非常感謝你! – plasmy

1

按照我在看你的日誌中的錯誤是在這條線:

android:background="@string/table_bg_color" 

嘗試所有的地方使用此行:

android:background="#0f6f0f" 

OR:

將XML文件保存在res/values/colors.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="table_bg_color">#0f6f0f</color> 
    <color name="translucent_red">#80ff0000</color> 
</resources> 

然後用這樣的:

android:background="@color/table_bg_color" 

感謝。