weixin_42120514 2020-09-22 11:08 采纳率: 0%
浏览 86
已采纳

requestFeature() must be called before adding content


import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.Nullable;


public class VerticalSeekBarActivity extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

                //这也写就不会报错
                //(什么情况下要把requestWindowFeature放到super.onCreate前面呢?)
                //requestWindowFeature(Window.FEATURE_NO_TITLE);
                //super.onCreate(savedInstanceState);

        }

}

这样写问什么会报错
requestFeature() must be called before adding content

在工作项目里报错了,新建的项目里面这也写又不会有问题

09-22 11:01:23.846 com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx.xxx, PID: 17610
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.tencent.android.tpush.TpnsActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2517)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
        at android.app.ActivityThread.access$1000(ActivityThread.java:166)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5619)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
     Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:352)
        at android.app.Activity.requestWindowFeature(Activity.java:3755)
        at com.tencent.android.tpush.TpnsActivity.onCreate(ProGuard:77)
        at android.app.Activity.performCreate(Activity.java:6351)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2470)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577) 
        at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5619) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
  • 写回答

2条回答 默认 最新

  • 精装机械师 2020-09-24 15:02
    关注

    错误说明已经很清楚,requestFeature必须在窗口添加容器之前调用,因为在super.onCreate()中父类做了相关操作,往窗口添加了容器,所以会报错

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化