Android 找不到方法视图。视图。getDisplay()
我相信有人发布了类似的错误,但一般来说,我只是在实现谷歌游戏服务API时遇到了麻烦 在onCreate()中创建Google客户端对象时,我遇到此日志错误: 我下载了Google客户端API的最新版本,我正在使用Eclipse 我的主要活动中的相关Google客户端代码:Android 找不到方法视图。视图。getDisplay(),android,runtime-error,google-client,Android,Runtime Error,Google Client,我相信有人发布了类似的错误,但一般来说,我只是在实现谷歌游戏服务API时遇到了麻烦 在onCreate()中创建Google客户端对象时,我遇到此日志错误: 我下载了Google客户端API的最新版本,我正在使用Eclipse 我的主要活动中的相关Google客户端代码: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.set
@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);
}
View.getDisplay()
是在API级别17中添加的,即Android 4.2。您可能正在使用以前版本的设备上执行代码。您或某些库可能仅在使用4.2+的设备中的某个点调用getDisplay()
,但是设备VM在某些代码路径上看到调用,并且它不知道该方法,因此它会替换它
但您的应用程序并不是因为
getDisplay()
而崩溃,而是因为您在调用setContentView
后,在第70行调用了Activity.requestWindowFeature
。至少StackTrace是这么说的。通过堆栈跟踪,您正在尝试在设置内容之后更改窗口功能。setContentView(R.layout.sign)
,您应该在设置内容之前调用requestWindowFeature显示您的代码AndroidGame。onCreate()是的,我的Droid恰好在4.1.2上!我没想到会把这段代码放到requestWindowFeature下面。现在我可以继续了,谢谢。
@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);
}