Question

I believe someone posted a similar error, but generally I have just been having trouble implementing Google Play Game Services API.

I am getting this log error when creating a Google Client object in onCreate():

05-10 15:06:05.490: E/Trace(23953): error opening trace file: No such file or directory (2)
05-10 15:06:05.490: D/ActivityThread(23953): setTargetHeapUtilization:0.25
05-10 15:06:05.490: D/ActivityThread(23953): setTargetHeapIdealFree:8388608
05-10 15:06:05.490: D/ActivityThread(23953): setTargetHeapConcurrentStart:2097152
05-10 15:06:05.930: I/dalvikvm(23953): Could not find method android.view.View.getDisplay, referenced from method com.google.android.gms.internal.gd$b.g
05-10 15:06:05.930: W/dalvikvm(23953): VFY: unable to resolve virtual method 3404: Landroid/view/View;.getDisplay ()Landroid/view/Display;
05-10 15:06:05.930: D/dalvikvm(23953): VFY: replacing opcode 0x6e at 0x0009
05-10 15:06:05.930: D/AndroidRuntime(23953): Shutting down VM
05-10 15:06:05.930: W/dalvikvm(23953): threadid=1: thread exiting with uncaught exception (group=0x4189a438)
05-10 15:06:05.940: E/AndroidRuntime(23953): FATAL EXCEPTION: main
05-10 15:06:05.940: E/AndroidRuntime(23953): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alexkidd.bitvsbit/com.alexkidd.bitgame.BitGame}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2132)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.os.Looper.loop(Looper.java:137)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread.main(ActivityThread.java:5021)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at java.lang.reflect.Method.invokeNative(Native Method)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at java.lang.reflect.Method.invoke(Method.java:511)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at dalvik.system.NativeStart.main(Native Method)
05-10 15:06:05.940: E/AndroidRuntime(23953): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
05-10 15:06:05.940: E/AndroidRuntime(23953):    at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.Activity.requestWindowFeature(Activity.java:3263)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at com.alexkidd.implement.AndroidGame.onCreate(AndroidGame.java:70)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.Activity.performCreate(Activity.java:5058)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-10 15:06:05.940: E/AndroidRuntime(23953):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
05-10 15:06:05.940: E/AndroidRuntime(23953):    ... 11 more

I downloaded the most recent version of the Google Client API and I am using Eclipse.

The relevant Google Client code in my Main Activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.signin);
    this.mGoogleClient = new GoogleApiClient.Builder(this, this, this)
    .addApi(Games.API)
    .addScope(Games.SCOPE_GAMES)
    .setViewForPopups(this.findViewById(R.id.sign_in_button))
    .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
    .build();

     mResolvingError = savedInstanceState != null
                && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    int frameBufferWidth = isPortrait ? 480 : 800;
    int frameBufferHeight = isPortrait ? 800 : 480;
    Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
            frameBufferHeight, Config.RGB_565);
    display = getWindowManager().getDefaultDisplay();
    checkDimens();
    // Scaling. Good 2 Go.
    float scaleX = (float) frameBufferWidth / width;
    float scaleY = (float) frameBufferHeight / height;

    renderView = new AndroidFastRenderView(this, frameBuffer);
    graphics = new AndroidGraphics(getAssets(), frameBuffer);
    fileIO = new AndroidFileIO(this);
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, renderView, scaleX, scaleY);
    screen = getInitScreen();
    lastScreen = screen;
    setContentView(renderView);
}
Was it helpful?

Solution

View.getDisplay() was added in API level 17, that is Android 4.2. You probably are executing the code on a device with a previous version. You or some library probably calls getDisplay() at some point only in devices with 4.2+ but the device VM sees the call on some code path, and it doesn't know about that method, so it replaces it.

But you app is not crashing due to getDisplay() but because on line 70 you are calling Activity.requestWindowFeature after you have called setContentView. At least that is what the StackTrace says.

OTHER TIPS

By the stack trace, your are trying to change window features after setting content this.setContentView(R.layout.signin), you should call requestWindowFeature before setting content

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top