{"id":954,"date":"2023-03-11T19:04:33","date_gmt":"2023-03-11T11:04:33","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=954"},"modified":"2023-04-29T13:31:38","modified_gmt":"2023-04-29T05:31:38","slug":"android-inflate-threw-nullpointerexception","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/11\/android-inflate-threw-nullpointerexception\/","title":{"rendered":"Android inflate()\u5f15\u53d1NullPointerException"},"content":{"rendered":"<p>\u4f7f\u7528<code>LayoutInflater<\/code>\u7684<code>inflate()<\/code>\u65b9\u6cd5\u6e32\u67d3View<\/p>\n<pre><code class=\"language-java\">View view = LayoutInflater.from(mContext).inflate(R.layout.layout_dialog, null);<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>\u62a5\u4e86\u4e00\u4e2a\u770b\u4f3c\u6beb\u65e0\u5173\u8054\u7684\u7a7a\u6307\u9488\u5f02\u5e38<\/p>\n<pre><code>java.lang.NullPointerException: Attempt to invoke virtual method &#039;boolean java.lang.String.equals(java.lang.Object)&#039; on a null object reference\n    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)\n    at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)\n    at android.view.LayoutInflater.inflate(LayoutInflater.java:508)\n    at android.view.LayoutInflater.inflate(LayoutInflater.java:418)\n    at com.android.internal.app.AlertController.setupView(AlertController.java:482)\n    at com.android.internal.app.AlertController.installContent(AlertController.java:239)\n    at android.app.AlertDialog.onCreate(AlertDialog.java:356)\n    at android.app.Dialog.dispatchOnCreate(Dialog.java:373)\n    at android.app.Dialog.show(Dialog.java:274)\n    at ch.appblog.test.ui.activity.MainActivity$3.onCreate(MainActivity.java:86)\n    at android.view.View.performClick(View.java:4811)\n    at android.view.View$PerformClick.run(View.java:20136)\n    at android.os.Handler.handleCallback(Handler.java:815)\n    at android.os.Handler.dispatchMessage(Handler.java:104)\n    at android.os.Looper.loop(Looper.java:194)\n    at android.app.ActivityThread.main(ActivityThread.java:5549)\n    at java.lang.reflect.Method.invoke(Native Method)\n    at java.lang.reflect.Method.invoke(Method.java:372)\n    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)\n    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)<\/code><\/pre>\n<p>\u901a\u8fc7\u6392\u67e5\u5e03\u5c40\u6587\u4ef6\uff0c<\/p>\n<pre><code class=\"language-xml\">&lt;view\n    style=&quot;@style\/Line_View&quot;\n    android:layout_height=&quot;1dp&quot;\n    \/&gt;<\/code><\/pre>\n<blockquote>\n<p>\u539f\u56e0\uff1a<code>&lt;view&gt;<\/code>\u6807\u7b7e\u7684v\u662f\u5c0f\u5199\u7684\uff0c\u5e94\u8be5\u662f<code>&lt;View&gt;<\/code>\uff0c\u8d44\u6e90\u6587\u4ef6\u7f16\u8bd1\u672a\u901a\u8fc7\uff0c\u4e0d\u8fc7<code>view<\/code>\u8ddf<code>View<\/code>\u771f\u7684\u6bd4\u8f83\u5bb9\u6613\u641e\u9519\uff0c\u800c\u4e14<code>Android Studio<\/code>\u4e5f\u4e0d\u4f1a\u63d0\u793a\u9519\u8bef<\/p>\n<\/blockquote>\n<p>\u6240\u4ee5\u7f16\u8bd1\u8fdb\u7a0b\u5361\u5728\u8fd9\u91cc\uff0c\u5e03\u5c40\u8d44\u6e90\u63a7\u4ef6\u672a\u8bc6\u522b\uff0c<code>inflate()<\/code>\u5f15\u7528\u4e86\u4e00\u4e2a\u7a7a\u7684\u5e03\u5c40\u6587\u4ef6id<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528LayoutInflater\u7684inflate()\u65b9\u6cd5\u6e32\u67d3View View view = LayoutIn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-954","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=954"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/954\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}