使用greendroid android时的ResourceNotFoundException

时间:2012-03-30 16:03:47

标签: android

美好的一天,我正在使用greendroid库在我的应用中添加一个操作栏功能。现在由于某种原因,我在尝试给特定布局膨胀时遇到ResourceNotFoundException错误。但如果我删除绿色机器人并只使用正常活动,它的工作原理。有人有任何想法吗?谢谢

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:background="#101319">


<RelativeLayout    
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"    
        android:text="@string/From:"
        android:textStyle="bold"
        android:id="@+id/from_text_id"
        android:padding="12dp">
    </TextView> 


    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/from_text_id"
        android:layout_marginTop="10dp"
        android:paddingTop="2dp"
        android:layout_weight="0.1"
        android:text="@string/myLocation"
        android:id="@+id/myLocationId">
    </Button>

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/myLocationId"
            android:layout_alignLeft="@id/myLocationId"
            android:hint="@string/enter_current_location"
            android:id="@+id/typeLocationId">
        </EditText> 

   <View 
       android:id="@+id/view1_id"
       android:layout_height="1dp"
       android:layout_width="0dp"
       android:layout_marginTop="20dp"
       android:background="#FF909090"/> 

  <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/typeLocationId"
            android:text="@string/Location"
            android:textSize="12sp"
            android:clickable="true"
            android:padding="20dp"
            android:gravity="center_vertical"
            android:id="@+id/startLocationId"
            android:focusable="true"
            android:background="@drawable/newitem_background">
    </TextView>

     <View 
       android:id="@+id/view2"
       android:layout_height="1dp"
       android:layout_width="0dp"
       android:paddingTop="40dp"
       android:background="#FF909090" />

       <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/layoutId"
        android:layout_below="@id/startLocationId"
        android:padding="20dp"
        android:paddingTop="10dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/newitem_background">

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/TO:"
            android:textStyle="bold"
            android:id="@+id/to_label_id">
        </TextView>

            <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/to_label_id"
            android:layout_marginLeft="5dp"
            android:text="@string/Location1"
            android:textSize="12sp"
            android:clickable="true"
            android:id="@+id/destLocationId"
            android:focusable="true">
            </TextView>

     <View 
        android:id="@+id/view3"
        android:layout_height="1dp"
        android:layout_width="0dp"
        android:background="#FF909090"/>

      </RelativeLayout>

        <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@id/layoutId"
        android:text="@string/getDirection"
        android:id="@+id/getDirectionId"
        android:gravity="center">
    </Button>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom">

<com.google.ads.AdView 
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>

</LinearLayout>

</RelativeLayout>
</LinearLayout>

这是我的logcat消息:

03-30 14:18:34.667: E/AndroidRuntime(554): Uncaught handler: thread main exiting due to uncaught exception
03-30 14:18:34.707: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyProject.Taap/com.MyProject.Taap.LocationViewer}: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.os.Looper.loop(Looper.java:123)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-30 14:18:34.707: E/AndroidRuntime(554):  at java.lang.reflect.Method.invokeNative(Native Method)
03-30 14:18:34.707: E/AndroidRuntime(554):  at java.lang.reflect.Method.invoke(Method.java:521)
03-30 14:18:34.707: E/AndroidRuntime(554):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-30 14:18:34.707: E/AndroidRuntime(554):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-30 14:18:34.707: E/AndroidRuntime(554):  at dalvik.system.NativeStart.main(Native Method)

03-30 14:18:34.707: E/AndroidRuntime(554): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-30 14:18:34.707: E/AndroidRuntime(554):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.Activity.setContentView(Activity.java:1622)
03-30 14:18:34.707: E/AndroidRuntime(554):  at greendroid.app.GDActivity.ensureLayout(GDActivity.java:187)
03-30 14:18:34.707: E/AndroidRuntime(554):  at greendroid.app.GDActivity.getContentView(GDActivity.java:286)
03-30 14:18:34.707: E/AndroidRuntime(554):  at greendroid.app.GDActivity.setActionBarContentView(GDActivity.java:305)
03-30 14:18:34.707: E/AndroidRuntime(554):  at com.MyProject.Taap.LocationViewer.onCreate(LocationViewer.java:133)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-30 14:18:34.707: E/AndroidRuntime(554):  ... 11 more

03-30 14:18:34.707: E/AndroidRuntime(554): Caused by: java.lang.reflect.InvocationTargetException
03-30 14:18:34.707: E/AndroidRuntime(554):  at greendroid.widget.ActionBar.<init>(ActionBar.java:130)
03-30 14:18:34.707: E/AndroidRuntime(554):  at java.lang.reflect.Constructor.constructNative(Native Method)
03-30 14:18:34.707: E/AndroidRuntime(554):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
03-30 14:18:34.707: E/AndroidRuntime(554):  ... 24 more

03-30 14:18:34.707: E/AndroidRuntime(554): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01002a a=-1}
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.content.res.Resources.loadDrawable(Resources.java:1677)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.View.<init>(View.java:1850)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.View.<init>(View.java:1799)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.view.ViewGroup.<init>(ViewGroup.java:284)
03-30 14:18:34.707: E/AndroidRuntime(554):  at android.widget.LinearLayout.<init>(LinearLayout.java:92)
03-30 14:18:34.707: E/AndroidRuntime(554):  at greendroid.widget.ActionBar.<init>(ActionBar.java:134)
03-30 14:18:34.707: E/AndroidRuntime(554):  ... 28 more

1 个答案:

答案 0 :(得分:1)

解决了它。问题出在清单中,由XML行24表示。显然,在活动标记中指定的主题属性不再用于布局,因此错误。我之前有过这个

<activity android:name=".LocationViewer" android:label="@string/app_name"android:theme="@style/Theme.D1" ></activity>

删除android:theme解决了问题。