java.lang.IllegalArgumentException:找不到id 0x7f0d00a0

时间:2017-08-26 07:29:30

标签: java android android-fragments

大家好,当我将数据从活动传递到片段时,我得到了这个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.materialtabs/info.androidhive.materialtabs.activity2.ScrollableTabsActivity2}: java.lang.IllegalArgumentException: No view found for id 0x7f0d00a0 (info.androidhive.materialtabs:id/acab) for fragment MyListFragment2{b731e17 #0 id=0x7f0d00a0}

这是传递数据的代码:

Bundle bundle = new Bundle();
            bundle.putIntegerArrayList("oki", hm);
            bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze);
MyListFragment2 myFragment = MyListFragment2.newInstance(hm,hm_quantitàpizze);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            //transaction.replace(android.R.id.content, myFragment);
            transaction.replace(R.id.acab, myFragment);

            transaction.commit();

其中R.id.acab是从活动中获取数据的片段的id!

这是FRAGMENT(从活动中获取数据)XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/acab"
    android:layout_marginLeft="5dp"

    >
    <ListView
        android:id="@+id/listvieww"
        android:layout_marginTop="120dp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    </ListView>




</FrameLayout>

现在我发布活动xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:orientation="horizontal" >

TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/welcome"
                    android:textSize="20dp"
                    android:layout_marginLeft="5dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20dp"
                    android:layout_marginLeft="5dp"
                    android:id="@+id/numero_tavolo"
                    />

                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:textColor="@color/lbl_name"
                    android:textSize="24dp"
                    android:layout_marginLeft="5dp"
                    />


            </LinearLayout>

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabss"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            android:background="@color/colorPrimaryDark" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpagerr"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    </android.support.v4.view.ViewPager>


</android.support.design.widget.CoordinatorLayout>

ACTIVTY:

public  class ScrollableTabsActivity2 extends AppCompatActivity {

    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private Button cazzo;
    //private SQLiteHandler db;
    private SessionManager session;
    private TextView txtName;
    private TextView txtEmail;
    int s;
    String intentt="";
    File file;
    Uri filePath;
    ListView lv;
    ArrayList<Integer> hm=new ArrayList<>();
    String path=null;
    ArrayList<Planet> planetList=new ArrayList();

    private String myString = "azz";
     ArrayList<Integer> arraylistInteger;
    String value="";
    String numero_tavolo="";
    ArrayList<Integer> hm3=new ArrayList<>();
    ArrayList<Integer> hm_quantitàpizze=new ArrayList<>();
    TextView numero_tavolo_text_view;


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


        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        txtName = (TextView) findViewById(R.id.name);
        txtEmail = (TextView) findViewById(R.id.numero_telefonico);
        numero_tavolo_text_view=(TextView)findViewById(R.id.numero_tavolo);



        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        viewPager = (ViewPager) findViewById(R.id.viewpagerr);
        setupViewPager(viewPager);

        tabLayout = (TabLayout) findViewById(R.id.tabss);
        tabLayout.setupWithViewPager(viewPager);


        Bundle extras = getIntent().getExtras();
        if (extras != null) {
             value = extras.getString("PATH FILE DA AGGIORNARE");
            numero_tavolo=extras.getString("NUMERO_TAVOLO");
            file = new File(value);
            System.out.println("FILE:" + file);

            FileInputStream is = null;
            try {
                is = new FileInputStream(file);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = null;
            try {
                dBuilder = dbFactory.newDocumentBuilder();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            }
            Document doc = null;
            try {
                doc = dBuilder.parse(is);
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            Element element = doc.getDocumentElement();
            element.normalize();

            int a;
            int b;
            NodeList nList = doc.getElementsByTagName("checkboxes_pizza");
            hm.clear();
            hm_quantitàpizze.clear();

            for (int i = 0; i < nList.getLength(); i++) {
                Node node = nList.item(i);

                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    Element element2 = (Element) node;
                    //tv1.setText(tv1.getText()+"\nName : " + getValue("name", element2)+"\n");

                    String id = getValue("id", element2);
                    a = Integer.parseInt(id);
                    String idd = getValue("quantita", element2);
                    b = Integer.parseInt(idd);


                    System.out.println("XMLLLLLLLLLL:" + b);

                    hm.add(a);
                    hm_quantitàpizze.add(b);

                    System.out.println("AZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ:" + hm_quantitàpizze);
                    System.out.println("LAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:" + hm);






                }

            }
            Bundle bundle = new Bundle();
            bundle.putIntegerArrayList("oki", hm);
            bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze);

            System.out.println("PERO:" + bundle);


            MyListFragment2 myFragment = MyListFragment2.newInstance(hm,hm_quantitàpizze);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            //transaction.replace(android.R.id.content, myFragment);
            transaction.replace(R.id.crisbio, myFragment);

            transaction.commit();


        }

       numero_tavolo_text_view.setText(numero_tavolo);
    }




    private static String getValue(String tag, Element element) {
        NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
        Node node = nodeList.item(0);
        return node.getNodeValue();
    }
/*cazzo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
               // logoutUser();
            }
        });*//*



      //  s = getIntent().getIntExtra("EXTRA_SESSION_ID",0);
       // System.out.println("IDDDDDDD" + s);

       // getMyData();
*/
/*
        Intent intent = getIntent();

        arraylistInteger = intent.getIntegerArrayListExtra("oki");
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("oki", arraylistInteger);

        Fragment fragment = new MyListFragment();
        fragment.setArguments(bundle);


        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.container, fragment);
        transaction.commit();
        System.out.println("PASSATO " + bundle);*//*

    }



   */
/* public int getMyData() {
        return s;

    }*//*



*/
/*    private void logoutUser() {

        Intent intent = new Intent();
        intent.setPackage("com.asus.filemanager");
        intent.setType("text/xml");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "LOGOUT"), 1);
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

      *//*
*/
/*  Intent intent = new Intent(ScrollableTabsActivity.this,
                ScrollableTabsActivity.class);

        startActivity(intent);*//*
*/
/*

        filePath = data.getData();
        System.out.println("FILEPATH" + filePath);


        path = FilePath.getPath(this, filePath);

        System.out.println("PATH" + path);

        int a=0;
        String status="";
        boolean statuss = false;
        String intenttt= path;

        System.out.println("INTENT:"+intenttt);



        file = new File(intenttt);
        System.out.println("FILE:"+file);

        FileInputStream is = null;
        try {
            is = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = null;
        try {
            dBuilder = dbFactory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        Document doc = null;
        try {
            doc = dBuilder.parse(is);
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Element element = doc.getDocumentElement();
        element.normalize();

        NodeList nList = doc.getElementsByTagName("checkboxes_pizza");

        for (int i = 0; i < nList.getLength(); i++) {
            Node node = nList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element2 = (Element) node;
                //tv1.setText(tv1.getText()+"\nName : " + getValue("name", element2)+"\n");

                String id = getValue("id", element2);
                a = Integer.parseInt(id);
                status = getValue("status", element2);

                statuss= Boolean.parseBoolean(status);

                System.out.println("XML:" + a);
                hm.clear();

                hm.add(a);

                System.out.println("AZZ:" + hm);





            }

        }



        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("oki", hm);

        Fragment fragment = new MyListFragment();
        fragment.setArguments(bundle);


        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.container, fragment);
        transaction.commit();
        System.out.println("PASSATO " + bundle);


    }*//*



    private static String getValue(String tag, Element element) {
        NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
        Node node = nodeList.item(0);
        return node.getNodeValue();
    }



   */
/* @Override
    protected void onPause() {
        super.onPause();
        logoutUser();
    }*/


    private void setupViewPager(ViewPager viewPager) {
        //ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        adapter.addFrag(new MyListFragment2(), "PIZZE");
        // adapter.addFrag(new SixFragment2(), "SIX");
        //adapter.addFrag(new FiveFragment2(), "TAVOLI");
        adapter.addFrag(new ThreeFragment2(), "BEVANDE");
        adapter.addFrag(new FourFragment2(), "STAMPA");
       // adapter.addFrag(new TwoFragment2(), "TWO");
        //adapter.addFrag(new SevenFragment2(), "SEVEN");
        //adapter.addFrag(new EightFragment2(), "EIGHT");
        //adapter.addFrag(new NineFragment2(), "NINE");
        //adapter.addFrag(new TenFragment2(), "TEN");


        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(10);
    }




    class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFrag(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }


}

谁能帮帮我?我希望你能帮助我!!!!!!!!!!!!!!!!!!!!

感谢

1 个答案:

答案 0 :(得分:0)

尝试使用此代码替换片段;

  Fragment fragment = new MyListFragment2();
  FragmentManager fm = getSupportFragmentManager();
  FragmentTransaction ft = fm.beginTransaction();
  ft.replace(R.id.acab, fragment);
  ft.commit();