requestFeature()必须添加错误之前调用 [英] requestFeature() must be called before adding error

查看:174
本文介绍了requestFeature()必须添加错误之前调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一个我不明白,在所有的,我想,像这样没有标题

This one I do not understand at all, I am trying to display a custom dialog with no title like this

d.setContentView(R.layout.incident_dialog_layout);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);

这样给我一个错误

doing this gives me an error

07-25 11:56:23.737: E/AndroidRuntime(15680): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:56:23.737: E/AndroidRuntime(15680):    at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1121)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.os.Looper.loop(Looper.java:137)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:56:23.737: E/AndroidRuntime(15680):    at dalvik.system.NativeStart.main(Native Method)

确定这很简单的只是改变那里的请求。所以,我再改成这样

ok that simple enough just change where the request is. So I then change it to this

d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.incident_dialog_layout);

对话框工作,直到我开始一个新的活动,当我回去,然后点击创建对话框我得到这个错误的项目

dialog works until I start a new activity when I go back and click on the item that creates the dialog I get this error

07-25 11:51:19.182: E/AndroidRuntime(15376): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:51:19.182: E/AndroidRuntime(15376):    at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1120)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.os.Looper.loop(Looper.java:137)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:51:19.182: E/AndroidRuntime(15376):    at dalvik.system.NativeStart.main(Native Method)

所以这是什么要我做的话,因为我不能拥有它后,我设置我的内容诺雷可以拥有它我发送的内容之前?????

so what does it want me to do then since I cant have it after I set the content nore can I have it before I sent the content?????

推荐答案

由于你第二次设置对话框布局(这是,当你从第二个活动背面)你得到这个错误,你已经在内容您的屏幕。

You are getting that error because the second time you set the dialog layout(this is, when you come back from the second activity), you already have content in your screen.

所以,调用requestWindowFeature这第二次导致错误。

So, calling requestWindowFeature this second time causes the error.

您将不得不这种说法搬到onCreate()方法,因此,只有一次被称为requestFeature,确保没有内容的调用之前被添加。

You'll have to move that statement to onCreate() method, hence only one time is called requestFeature, ensuring no content is added before its call.

这篇关于requestFeature()必须添加错误之前调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆