-1

执行我的应用程序后,我一直在模拟器中收到此错误。如果有人能通读这篇文章并在这里帮助我,那就太棒了。如有错误请指出。

我的 activity_fullscreen.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:animateLayoutChanges="true"
android:background="#000000"
android:onClick="hideSoftKeyboard"
tools:context=".FullscreenActivity" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="412dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:fitsSystemWindows="true"
    android:orientation="vertical" >

</LinearLayout>

<Button
    android:id="@+id/button"
    android:layout_width="231dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="93dp"
    android:text="Search" />

<EditText
    android:id="@+id/fullscreen_content"
    android:layout_width="311dp"
    android:layout_height="73dp"
    android:layout_above="@+id/button"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="21dp"
    android:ems="8"
    android:imeOptions="actionSearch"
    android:inputType="textCapWords"
    android:textColor="#FFFFFF"
    android:textSize="20sp"
    android:textStyle="bold|normal" />

我的 FullscreenActivity.java

public class FullscreenActivity extends Activity {

Button mButton;         //Button
EditText mEdit;         //Text box
String query;       
View lLayout;           //LinearLayout

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        //Code for full screen activity
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mButton = (Button)findViewById(R.id.button);
    mEdit   = (EditText)findViewById(R.id.fullscreen_content);
    lLayout = (View)findViewById(R.id.linearLayout1);

    mButton.setOnClickListener(
        new View.OnClickListener()
        {
            public void onClick(View view)
            {
                query=mEdit.getText().toString();
                Intent res=new Intent(FullscreenActivity.this,ResultActivity.class);
                startActivity(res);
            }
        });

    lLayout.setOnClickListener(
            new View.OnClickListener()
            {
                public void onClick(View view)
                {
                    hideSoftKeyboard();
                }
            });
}


private void hideSoftKeyboard(){
    if(getCurrentFocus()!=null && getCurrentFocus() instanceof EditText){
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        View yourEditTextHere =(View)findViewById(R.id.fullscreen_content);
        imm.hideSoftInputFromWindow(yourEditTextHere.getWindowToken(), 0);
    }
}

}

我的日志:

 06-13 13:58:50.291: E/Trace(669): error opening trace file: No such file or directory (2)
 06-13 13:58:51.611: D/AndroidRuntime(669): Shutting down VM
 06-13 13:58:51.611: W/dalvikvm(669): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
 06-13 13:58:51.641: E/AndroidRuntime(669): FATAL EXCEPTION: main
 06-13 13:58:51.641: E/AndroidRuntime(669): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vearch/com.example.vearch.FullscreenActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.os.Handler.dispatchMessage(Handler.java:99)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.os.Looper.loop(Looper.java:137)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread.main(ActivityThread.java:4745)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at java.lang.reflect.Method.invokeNative(Native Method)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at java.lang.reflect.Method.invoke(Method.java:511)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at dalvik.system.NativeStart.main(Native Method)
 06-13 13:58:51.641: E/AndroidRuntime(669): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
 06-13 13:58:51.641: E/AndroidRuntime(669):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.Activity.requestWindowFeature(Activity.java:3225)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at com.example.vearch.FullscreenActivity.onCreate(FullscreenActivity.java:27)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.Activity.performCreate(Activity.java:5008)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
 06-13 13:58:51.641: E/AndroidRuntime(669):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
 06-13 13:58:51.641: E/AndroidRuntime(669):     ... 11 more
4

2 回答 2

3

正如异常中的消息所暗示的,您必须搬家

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        //Code for full screen activity
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView

于 2013-06-14T08:53:16.607 回答
0

在添加内容之前必须调用 requestFeature()

=>requestFeature()在添加内容之前调用。(setContentView()在你的情况下)

于 2013-06-14T08:58:52.430 回答