1

This is my code from where I am accessing search_product_item.xml

 @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);

This is search_product_item XML file

<?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>

My 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

I cleaned my project 100 times and restart the eclipse But problem didn't resolve. Please provide the solution.

Arjun Singh
  • 724
  • 1
  • 8
  • 24
ashish
  • 11
  • 2
  • have a look [here](http://stackoverflow.com/questions/21269502/android-resourcesnotfoundexception-resource-id-0x7f030027). This will certainly help you. – Shree Krishna Mar 01 '16 at 06:25

3 Answers3

0

Is your .xml file in res folder?

If yes put it inside res/layout/file.xml

Bala Raja
  • 627
  • 6
  • 20
  • i am using this file for nexus 9 and it is not working.yes i put this file in layout-sw720dp folder but it is not getting – ashish Mar 01 '16 at 12:08
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);

            }
Khizar Hayat
  • 3,427
  • 3
  • 18
  • 22
0

Replace this:

    @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      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);

      }

   setContentView(R.layout.search_product_item);

By 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);

      }

Actually u were taking layout outside onCreate. Thanks

Arjun Singh
  • 724
  • 1
  • 8
  • 24
  • Post your Manifest. I think u didn't mentioned your Activity in Manifest. OR MAKE CHANGES LIKE: public class "YOURACTIVITYNAME" extends AppCompatActivity at the top of this activity.java file. – Arjun Singh Mar 02 '16 at 03:52