本文介绍了的getSize()给我的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我实现了。
窗口管理WM =((窗口管理器)context.getSystemService(context.WINDOW_SERVICE));
显示显示= wm.getDefaultDisplay();
m_nDisplayWidth = display.getWidth();
m_nDisplayHeight = display.getHeight();
我可以运行得很好,但是当我实现了我的getSize得到runtimeError
点大小=新的点();
display.getSize(大小); //错误就在这里
m_nDisplayWidth = size.x;
m_nDisplayHeight = size.y;
logcat的:
1月3日至11号:45:25.865:E / AndroidRuntime(18835):致命异常:主要
一月三日至11日:45:25.865:E / AndroidRuntime(18835):android.view.InflateException:二进制XML文件中的行#7:错误充气类com.brain.development.GameRun
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.createView(LayoutInflater.java:518)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.inflate(LayoutInflater.java:408)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.inflate(LayoutInflater.java:320)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.inflate(LayoutInflater.java:276)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.app.Activity.setContentView(Activity.java:1679)
一月3日至11号:45:25.865:E / AndroidRuntime(18835):在com.brain.development.BrainDevelopmentActivity $ 1.onClick(BrainDevelopmentActivity.java:25)一月三号至11号:45:25.865:E / AndroidRuntime(18835):在android.view.View.performClick(View.java:2582)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.View $ PerformClick.run(View.java:9252)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.os.Handler.handleCallback(Handler.java:587)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.os.Handler.dispatchMessage(Handler.java:92)
一月3日至11号:45:25.865:E / AndroidRuntime(18835):在android.os.Looper.loop(Looper.java:130)一月三号至11号:45:25.865:E / AndroidRuntime(18835):在机器人。 app.ActivityThread.main(ActivityThread.java:3691)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在java.lang.reflect.Method.invokeNative(本机方法)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在java.lang.reflect.Method.invoke(Method.java:507)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:907)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在dalvik.system.NativeStart.main(本机方法)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):由:java.lang.reflect.InvocationTargetException
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在java.lang.reflect.Constructor.constructNative(本机方法)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在java.lang.reflect.Constructor.newInstance(Constructor.java:415)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):在android.view.LayoutInflater.createView(LayoutInflater.java:505)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):19 ...更多
一月三日至11日:45:25.865:E / AndroidRuntime(18835):java.lang.NoSuchMethodError:产生的原因android.view.Display.getSize
。一月3日至11日:45:25.865:E / AndroidRuntime(18835):在com.brain.development.GameRun $ GameThread< INIT>(GameRun.java:46)
。一月3日至11日:45:25.865:E / AndroidRuntime(18835):在com.brain.development.GameRun< INIT>(GameRun.java:97)
一月三日至11日:45:25.865:E / AndroidRuntime(18835):22 ...更多
解决方案
这同时支持新旧设备:
私有静态点getDisplaySize(最终显示显示器){
最后一点一点=新的点();
尝试 {
display.getSize(点);
}赶上(java.lang.NoSuchMethodError忽略){//旧的设备
point.x = display.getWidth();
point.y = display.getHeight();
}
返回点;
}
When I implement
WindowManager wm = ((WindowManager)context.getSystemService(context.WINDOW_SERVICE));
Display display = wm.getDefaultDisplay();
m_nDisplayWidth = display.getWidth();
m_nDisplayHeight = display.getHeight();
I can run fine, but when I implement getSize I get runtimeError
Point size = new Point();
display.getSize(size); //Error right here
m_nDisplayWidth = size.x;
m_nDisplayHeight = size.y;
Logcat:
03-11 01:45:25.865: E/AndroidRuntime(18835): FATAL EXCEPTION: main
03-11 01:45:25.865: E/AndroidRuntime(18835): android.view.InflateException: Binary XML file line #7: Error inflating class com.brain.development.GameRun
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.app.Activity.setContentView(Activity.java:1679)
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.brain.development.BrainDevelopmentActivity$1.onClick(BrainDevelopmentActivity.java:25) 03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.View.performClick(View.java:2582)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.View$PerformClick.run(View.java:9252)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.os.Handler.handleCallback(Handler.java:587)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.os.Handler.dispatchMessage(Handler.java:92)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.os.Looper.loop(Looper.java:130) 03-11 01:45:25.865: E/AndroidRuntime(18835): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-11 01:45:25.865: E/AndroidRuntime(18835): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 01:45:25.865: E/AndroidRuntime(18835): at java.lang.reflect.Method.invoke(Method.java:507)
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
03-11 01:45:25.865: E/AndroidRuntime(18835): at dalvik.system.NativeStart.main(Native Method)
03-11 01:45:25.865: E/AndroidRuntime(18835): Caused by: java.lang.reflect.InvocationTargetException
03-11 01:45:25.865: E/AndroidRuntime(18835): at java.lang.reflect.Constructor.constructNative(Native Method)
03-11 01:45:25.865: E/AndroidRuntime(18835): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
03-11 01:45:25.865: E/AndroidRuntime(18835): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
03-11 01:45:25.865: E/AndroidRuntime(18835): ... 19 more
03-11 01:45:25.865: E/AndroidRuntime(18835): Caused by: java.lang.NoSuchMethodError: android.view.Display.getSize
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.brain.development.GameRun$GameThread.<init>(GameRun.java:46)
03-11 01:45:25.865: E/AndroidRuntime(18835): at com.brain.development.GameRun.<init>(GameRun.java:97)
03-11 01:45:25.865: E/AndroidRuntime(18835): ... 22 more
解决方案
This supports both older and newer devices:
private static Point getDisplaySize(final Display display) {
final Point point = new Point();
try {
display.getSize(point);
} catch (java.lang.NoSuchMethodError ignore) { // Older device
point.x = display.getWidth();
point.y = display.getHeight();
}
return point;
}
这篇关于的getSize()给我的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!