gpt4 book ai didi

android - inflatedView 的问题

转载 作者:行者123 更新时间:2023-11-29 22:21:36 25 4
gpt4 key购买 nike

我试图膨胀一个 View 作为我的 glSurfaceView 的加载屏幕,同时它在运行时交换纹理(我知道如何在我的 onCreate 期间做到这一点美好的)。它只是一个 RelativeLayout,中间有一个进度条,完成交换后它会消失,但它没有正确膨胀。

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

其中 loadingScreen 是相对布局的 ID。

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loadingScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:visibility="visible" >

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
</ProgressBar>

<EditText
android:id="@+id/editText android:layout_height="
android:layout_width="wrap_content"
wrap_content="" >
</EditText>

</RelativeLayout>

为了进行测试,我在以下附加代码上方添加了一个 EditText 以对其进行测试:

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

和错误日志:

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.<init>(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.<init>(CampusMapOpenGL.java:101)
08-12 15:07:35.653: ERROR/AndroidRuntime(2502): ... 24 more

最佳答案

尝试 loading.findViewById(...) 而不是 findViewById(...)

关于android - inflatedView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7044945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com