0

I have imported an eclipse project into android studio. In android studio the project was running without any hitches. However when using android studio, the app crashes. This is caused by use of a custom title bar. Here is my code:

public class WelcomeActivity extends ActionBarActivity implements
    OnClickListener {
TextView terms, proceed;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.activity_welcome);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.startup_windows_title);

    terms = (TextView) findViewById(R.id.textViewTerms);
    proceed = (TextView) findViewById(R.id.textViewProceed);

    Intent i = new Intent(this, ChatHeadDrawerService.class);
    startService(i);

    terms.setOnClickListener(this);
    proceed.setOnClickListener(this);
}

And the logcat content:

  01-05 12:28:31.457    6080-6080/com.gigavia.gigit E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gigavia.gigit/com.gigavia.gigit.WelcomeActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1972)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1997)
            at android.app.ActivityThread.access$600(ActivityThread.java:124)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1148)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4440)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:210)
            at android.app.Activity.requestWindowFeature(Activity.java:3083)
            at com.gigavia.gigit.WelcomeActivity.onCreate(WelcomeActivity.java:19)
            at android.app.Activity.performCreate(Activity.java:4465)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1936)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1997)
            at android.app.ActivityThread.access$600(ActivityThread.java:124)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1148)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4440)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
            at dalvik.system.NativeStart.main(Native Method)

The error is on this line

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

How do I overcome this?

Tim
  • 38,263
  • 17
  • 115
  • 131
mungaih pk
  • 1,715
  • 8
  • 27
  • 56

1 Answers1

0

Try anyone of it. will may helpful to you.

    @Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenu);
}



@Override
protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.startup_windows_title);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.info);

 }
chain
  • 589
  • 9
  • 22