Android學習開發——android Unable to inflate view tag without class attribute

根據《第一行代碼》裏面的第四章中製做一個利用碎皮合理佈局的新聞應用,發現編譯成功後,沒有提示任何編譯錯誤。可是在運行APP後,點擊RecyclerView裏面的新聞標題,準備進行活動跳轉,軟件直接異常終止。java

發現新聞內容顯示活動裏面的業務邏輯代碼確實沒有問題,跳轉也沒有問題。運行窗口提示:android

Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.droid/com.droid.activitys.UserCenterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference編輯器

而後佈局文件出錯佈局

AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class(這是其中報錯的最主要的一行信息)。.net

經過找尋網上解決方法,本身也打了斷點調試程序,發如今代碼setContentView處直接異常調試

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_content_layout);

        String newsTitle = getIntent().getStringExtra("news_title");
        String newsContent = getIntent().getStringExtra("news_content");
        if (newsTitle.isEmpty() || newsContent.isEmpty())
        {
            return;
        }
        NewsContentFragment newsContentFragment = (NewsContentFragment)getSupportFragmentManager().findFragmentById(R.id.news_content_fragment);
        newsContentFragment.refresh(newsTitle,newsContent);
    }

那麼確實是解析XML佈局文件,構建視圖界面的時候出錯了。開始去查看界面佈局文件,發現可視編輯器提示 android Unable to inflate view tag without class attributecode

那說明佈局內容有問題,或者子佈局,控件有問題。我開始看一篇的時候沒發現有問題。直到找到網上博客博主犯了一樣的錯誤http://blog.csdn.net/chaoxionghuai/article/details/68944129。xml

在news_content_frag.xml中我把中間分隔線的類名大小寫寫錯了。blog

<View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000">
        </View>

因此致使程序異常終止。找了好久的緣由。小小的錯誤直接影響大的效果。get

因此得注意佈局文件必定要正確解析。

 

成功單頁顯示新聞內容:

xiaoguo11

 

xiaoguotable

相關文章
相關標籤/搜索