2016-03-01 18 views
0

這是從哪兒我訪問search_product_item.xml我的代碼無法從佈局獲得資源訪問XML文件中未發現異常和XML文件是在res文件夾

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if (RootUtil.isDeviceRooted()) 
      finish(); 
     if (getResources().getBoolean(R.bool.portrait)) { 
      SPAN_COUNT = 2; 
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     } else { 
      SPAN_COUNT = 4; 
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

     } 

     setContentView(R.layout.search_product_item); 

這是search_product_item XML文件

<?xml version="1.0" encoding="UTF-8"?> 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
    android:orientation="vertical" > 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar_main" /> 

    <include 
     android:id="@+id/footerLinkView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     layout="@layout/layout_footer_link_view" /> 

    <include 
     android:id="@+id/footerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/footerLinkView" 
     layout="@layout/layout_footer" /> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/footerView" 
     android:layout_below="@+id/toolbar" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 

我logcat的

 03-01 11:01:01.399: E/AndroidRuntime(20344): FATAL EXCEPTION: main 
    03-01 11:01:01.399: E/AndroidRuntime(20344): Process: 

com.pg.dentistpartnerapp.mt, PID: 20344 
03-01 11:01:01.399: E/AndroidRuntime(20344): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pg.dentistpartnerapp.mt/com.pg.dentistpartnerapp.mt.activities.SearchagainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030048 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread.access$800(ActivityThread.java:144) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.os.Handler.dispatchMessage(Handler.java:102) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.os.Looper.loop(Looper.java:135) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread.main(ActivityThread.java:5221) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at java.lang.reflect.Method.invoke(Native Method) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at java.lang.reflect.Method.invoke(Method.java:372) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
03-01 11:01:01.399: E/AndroidRuntime(20344): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030048 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.content.res.Resources.getValue(Resources.java:1233) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2598) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.content.res.Resources.getLayout(Resources.java:1049) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.view.LayoutInflater.inflate(LayoutInflater.java:412) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at com.pg.dentistpartnerapp.mt.activities.SearchagainActivity.onCreate(SearchagainActivity.java:120) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.Activity.performCreate(Activity.java:5933) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
03-01 11:01:01.399: E/AndroidRuntime(20344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 
03-01 11:01:01.399: E/AndroidRuntime(20344): ... 10 more 

我打掃我的項目100倍,重啓eclipse但問題沒有解決。請提供解決方案。

+0

看看[這裏](http://stackoverflow.com/questions/21269502/android-resourcesnotfoundexception-resource-id-0x7f030027)。這一定會對你有所幫助。 –

回答

0

您的.xml文件是否在res文件夾中?

如果是將其放在RES /佈局/ file.xml

+0

我使用這個文件的nexus 9,它不工作。我把這個文件在layout-sw720dp文件夾,但它沒有得到 – ashish

0
try this 
    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.search_product_item); 
      if (RootUtil.isDeviceRooted()) 
       finish(); 
      // Log.d(TAG, "onCreate()"); 

      if (getResources().getBoolean(R.bool.portrait)) { 
       SPAN_COUNT = 2; 
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
      } else { 
       SPAN_COUNT = 4; 
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

      } 
+0

我試過這個,但也沒有工作 – ashish

+0

在哪個文件夾你有你的XML文件? –

0

替換此:

​​

通過這樣的:

 @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.search_product_item); 

     if (RootUtil.isDeviceRooted()) 
      finish(); 
     // Log.d(TAG, "onCreate()"); 

     if (getResources().getBoolean(R.bool.portrait)) { 
      SPAN_COUNT = 2; 
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     } else { 
      SPAN_COUNT = 4; 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

     } 

其實ü服用佈局之外的onCreate 。謝謝

+0

我在裏面,但它不工作 – ashish

+0

張貼你的清單。我認爲你沒有提到你在清單中的活動。或進行類似變更:公共類「YOURACTIVITYNAME」將AppCompatActivity擴展到此activity.java文件的頂部。 –

相關問題