problems inflating a view-Collection of common programming errors

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 not inflating correctly.

inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    loading = inflater.inflate(R.layout.loading,null);
RelativeLayout loadingScreen = (RelativeLayout) findViewById(R.id.loadingScreen);

where loadingScreen is the id of the relative layout.

xml:




    
    

    
    


For a test, I added an EditText above the following additional code to test it out:

EditText tester = (EditText) findViewById(R.id.editText); //Now we have an object
    tester.setText("dfdfds");

and the error log:

08-12 15:07:35.630: ERROR/ActivityThread(2502): Failed to inflate
08-12 15:07:35.630: ERROR/ActivityThread(2502): android.view.InflateException: Binary XML file line #5: Error inflating class com.huskybus.CampusMapOpenGL
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.Activity.setContentView(Activity.java:1657)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at com.huskybus.Main.onCreate(Main.java:91)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.os.Looper.loop(Looper.java:130)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at java.lang.reflect.Method.invoke(Method.java:507)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at dalvik.system.NativeStart.main(Native Method)
08-12 15:07:35.630: ERROR/ActivityThread(2502): Caused by: java.lang.reflect.InvocationTargetException
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     ... 21 more
08-12 15:07:35.630: ERROR/ActivityThread(2502): Caused by: java.lang.NullPointerException
08-12 15:07:35.630: ERROR/ActivityThread(2502):     at com.huskybus.CampusMapOpenGL.(CampusMapOpenGL.java:101)
08-12 15:07:35.630: ERROR/ActivityThread(2502):     ... 24 more
08-12 15:07:35.637: DEBUG/AndroidRuntime(2502): Shutting down VM
08-12 15:07:35.637: WARN/dalvikvm(2502): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502): FATAL EXCEPTION: main
08-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
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.os.Looper.loop(Looper.java:130)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at java.lang.reflect.Method.invoke(Method.java:507)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at dalvik.system.NativeStart.main(Native Method)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class com.huskybus.CampusMapOpenGL
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.Activity.setContentView(Activity.java:1657)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at com.huskybus.Main.onCreate(Main.java:91)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     ... 11 more
08-12 15:07:35.653: ERROR/AndroidRuntime(2502): Caused by: java.lang.reflect.InvocationTargetException
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     ... 21 more
08-12 15:07:35.653: ERROR/AndroidRuntime(2502): Caused by: java.lang.NullPointerException
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     at com.huskybus.CampusMapOpenGL.(CampusMapOpenGL.java:101)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502):     ... 24 more
  1. Try loading.findViewById(…) instead of just findViewById(…)

  2. 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.

  3. When you have inflatet the View you need to use that view when finding child views like this

        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        loading = inflater.inflate(R.layout.loading,null);
        RelativeLayout loadingScreen = (RelativeLayout) loading.findViewById(R.id.loadingScreen);