Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android-5.0-lollipop – 如何修复’你必须在include标签中指定一个布局:’大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Android工作室使用材料设计为前棒棒糖设备创建一个Android应用程序,我是android工作室的新手我正在我的项目中创建一个工具栏但我收到一个错误名为“引起:android.view.InflateException:你必须在include标签中指定一个布局:“请帮我解决这个问题,这是我的活动代码
package sample.lakshman.com.sampleltester;

import android.support.v7.app.ActionBarActivity;
import android.os.bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;


public class MainActivity extends ActionBarActivity {
    public Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.tool_bar);
        setSupportActionBar(toolbar);
    }


    @Override
    public Boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main,menu);
        return true;
    }

    @Override
    public Boolean onOptionsItemSELEcted(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button,so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_setTings) {
            return true;
        }

        return super.onOptionsItemSELEcted(item);
    }
}

这是我的xml:

<RelativeLayout xmlns:android="http://@R_450_10906@mas.android.com/apk/res/android"
    xmlns:tools="http://@R_450_10906@mas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/tool_bar"
        android:layout="@layout/tool_bar" />
</RelativeLayout>

这是我的工具栏Xml:

<?xml version="1.0" encoding="utf-8"?>
    <android.widget.Toolbar xmlns:android="http://@R_450_10906@mas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:BACkground="#E91E63">

    </android.widget.Toolbar>


This is my logcat:
 03-06 13:09:39.313  17890-17890/sample.lakshman.com.sampleltester E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: sample.lakshman.com.sampleltester,PID: 17890
        java.lang.RuntimeException: Unable to start activity ComponenTinfo{sample.lakshman.com.sampleltester/sample.lakshman.com.sampleltester.MainActivity}: android.view.InflateException: You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
                at android.app.ActivityThread.access$800(ActivityThread.java:151)
                at android.app.ActivityThread$H.handlemessage(ActivityThread.java:1321)
                at android.os.Handler.dispatchmessage(Handler.java:110)
                at android.os.Looper.loop(Looper.java:193)
                at android.app.ActivityThread.main(ActivityThread.java:5292)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: android.view.InflateException: You must specifiy a layout in the include tag: <include layout="@layout/layoutID" />
                at android.view.LayoutInflater.parseInclude(LayoutInflater.java:787)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
                at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
                at sample.lakshman.com.sampleltester.MainActivity.onCreate(MainActivity.java:16)
                at android.app.Activity.performCreate(Activity.java:5264)
                at android.app.instrumentation.callActivityOnCreate(instrumentation.java:1088)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handlemessage(ActivityThread.java:1321)
    at android.os.Handler.dispatchmessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
    at dalvik.system.NativeStart.main(Native Method)

解决方法

我找到了自己问题的答案.在我的工具activity_main xml布局中,我用layout =“@ layout / tool_bar”替换了android:layout =“@ layout / tool_bar”,并在工具栏布局中使用android.support.v7.widget.Tool bar替换了android.widget.Toolbar
查看我的两个xml文件
<RelativeLayout xmlns:android="http://@R_450_10906@mas.android.com/apk/res/android"
    xmlns:tools="http://@R_450_10906@mas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/tool_bar"
        android:layout="@layout/tool_bar" />
</RelativeLayout>

更正并使用Xml:

<RelativeLayout xmlns:android="http://@R_450_10906@mas.android.com/apk/res/android"
    xmlns:tools="http://@R_450_10906@mas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar" />
</RelativeLayout>

为了反思,请参阅答案here

大佬总结

以上是大佬教程为你收集整理的android-5.0-lollipop – 如何修复’你必须在include标签中指定一个布局:’全部内容,希望文章能够帮你解决android-5.0-lollipop – 如何修复’你必须在include标签中指定一个布局:’所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。