{"id":2272,"date":"2022-08-30T15:23:29","date_gmt":"2022-08-30T15:23:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/problems-inflating-a-view-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:29","modified_gmt":"2022-08-30T15:23:29","slug":"problems-inflating-a-view-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problems-inflating-a-view-collection-of-common-programming-errors\/","title":{"rendered":"problems inflating a view-Collection of common programming errors"},"content":{"rendered":"<p>Im trying to inflate a view which serves as a loading screen for my <code>glSurfaceView<\/code> while it swaps out textures during runtime (i know how to do it during my <code>onCreate<\/code> just fine). Its just a <code>RelativeLayout<\/code> with a progress bar in the middle and when its done with the swap it disappears, but its not inflating correctly.<\/p>\n<pre><code>inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\n    loading = inflater.inflate(R.layout.loading,null);\nRelativeLayout loadingScreen = (RelativeLayout) findViewById(R.id.loadingScreen);\n<\/code><\/pre>\n<p>where loadingScreen is the id of the relative layout.<\/p>\n<p>xml:<\/p>\n<pre><code>\n\n\n    \n    \n\n    \n    \n\n\n<\/code><\/pre>\n<p>For a test, I added an EditText above the following additional code to test it out:<\/p>\n<pre><code>EditText tester = (EditText) findViewById(R.id.editText); \/\/Now we have an object\n    tester.setText(\"dfdfds\");\n<\/code><\/pre>\n<p>and the error log:<\/p>\n<pre><code>08-12 15:07:35.630: ERROR\/ActivityThread(2502): Failed to inflate\n08-12 15:07:35.630: ERROR\/ActivityThread(2502): android.view.InflateException: Binary XML file line #5: Error inflating class com.huskybus.CampusMapOpenGL\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.Activity.setContentView(Activity.java:1657)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at com.huskybus.Main.onCreate(Main.java:91)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.os.Handler.dispatchMessage(Handler.java:99)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.os.Looper.loop(Looper.java:130)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.app.ActivityThread.main(ActivityThread.java:3835)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at java.lang.reflect.Method.invokeNative(Native Method)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at java.lang.reflect.Method.invoke(Method.java:507)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at dalvik.system.NativeStart.main(Native Method)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502): Caused by: java.lang.reflect.InvocationTargetException\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at java.lang.reflect.Constructor.constructNative(Native Method)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     ... 21 more\n08-12 15:07:35.630: ERROR\/ActivityThread(2502): Caused by: java.lang.NullPointerException\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     at com.huskybus.CampusMapOpenGL.(CampusMapOpenGL.java:101)\n08-12 15:07:35.630: ERROR\/ActivityThread(2502):     ... 24 more\n08-12 15:07:35.637: DEBUG\/AndroidRuntime(2502): Shutting down VM\n08-12 15:07:35.637: WARN\/dalvikvm(2502): threadid=1: thread exiting with uncaught exception (group=0x40015560)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502): FATAL EXCEPTION: main\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.huskybus\/com.huskybus.Main}: android.view.InflateException: Binary XML file line #5: Error inflating class com.huskybus.CampusMapOpenGL\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.os.Handler.dispatchMessage(Handler.java:99)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.os.Looper.loop(Looper.java:130)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread.main(ActivityThread.java:3835)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at java.lang.reflect.Method.invokeNative(Native Method)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at java.lang.reflect.Method.invoke(Method.java:507)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at dalvik.system.NativeStart.main(Native Method)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class com.huskybus.CampusMapOpenGL\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.Activity.setContentView(Activity.java:1657)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at com.huskybus.Main.onCreate(Main.java:91)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     ... 11 more\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502): Caused by: java.lang.reflect.InvocationTargetException\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at java.lang.reflect.Constructor.constructNative(Native Method)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     ... 21 more\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502): Caused by: java.lang.NullPointerException\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     at com.huskybus.CampusMapOpenGL.(CampusMapOpenGL.java:101)\n08-12 15:07:35.653: ERROR\/AndroidRuntime(2502):     ... 24 more\n<\/code><\/pre>\n<ol>\n<li>\n<p>Try loading.findViewById(&#8230;) instead of just findViewById(&#8230;)<\/p>\n<\/li>\n<li>\n<p>i also have these kind of errors.i found that the error is come because of my text editor name is not match with the my text editor id.<\/p>\n<\/li>\n<li>\n<p>When you have inflatet the View you need to use that view when finding child views like this<\/p>\n<pre><code>    inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\n    loading = inflater.inflate(R.layout.loading,null);\n    RelativeLayout loadingScreen = (RelativeLayout) loading.findViewById(R.id.loadingScreen);\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 09:41:22. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Im trying to inflate a view which serves as a loading screen for my glSurfaceView while it swaps out textures during runtime (i know how to do it during my onCreate just fine). Its just a RelativeLayout with a progress bar in the middle and when its done with the swap it disappears, but its [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2272","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2272"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2272\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}