From a2603d70ef0013eafb9c1d8af7d50b206902f648 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 12 Dec 2016 11:44:31 +0800 Subject: [PATCH] =?UTF-8?q?[android]=20Catches=20=E2=80=98NumberFormatExce?= =?UTF-8?q?ption=E2=80=99=20while=20invoking=20Integer.parseInt.=20(#16988?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [android] Catches ‘NumberFormatException’ while invoking Integer.parseInt. * [android] Catches ‘NullPointerException’ while converting Integer to int in Cocos2dxActivity.hideVirtualButton. --- .../org/cocos2dx/lib/Cocos2dxActivity.java | 39 +++++++++++-------- .../src/org/cocos2dx/lib/Cocos2dxHelper.java | 9 +++-- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 24bb0f1761..808cba473c 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -422,24 +422,29 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // use reflection to remove dependence of API level Class viewClass = View.class; - final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); - final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN"); - final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); - final int SYSTEM_UI_FLAG_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN"); - final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY"); - final int SYSTEM_UI_FLAG_LAYOUT_STABLE = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); - // getWindow().getDecorView().setSystemUiVisibility(); - final Object[] parameters = new Object[]{SYSTEM_UI_FLAG_LAYOUT_STABLE - | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar - | SYSTEM_UI_FLAG_FULLSCREEN // hide status bar - | SYSTEM_UI_FLAG_IMMERSIVE_STICKY}; - Cocos2dxReflectionHelper.invokeInstanceMethod(getWindow().getDecorView(), - "setSystemUiVisibility", - new Class[]{Integer.TYPE}, - parameters); + try { + final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION"); + final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN"); + final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); + final int SYSTEM_UI_FLAG_FULLSCREEN = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN"); + final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY"); + final int SYSTEM_UI_FLAG_LAYOUT_STABLE = Cocos2dxReflectionHelper.getConstantValue(viewClass, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); + + // getWindow().getDecorView().setSystemUiVisibility(); + final Object[] parameters = new Object[]{SYSTEM_UI_FLAG_LAYOUT_STABLE + | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar + | SYSTEM_UI_FLAG_FULLSCREEN // hide status bar + | SYSTEM_UI_FLAG_IMMERSIVE_STICKY}; + Cocos2dxReflectionHelper.invokeInstanceMethod(getWindow().getDecorView(), + "setSystemUiVisibility", + new Class[]{Integer.TYPE}, + parameters); + } catch (NullPointerException e) { + Log.e(TAG, "hideVirtualButton", e); + } } } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index 6ae9fb6a39..f4fb62d92c 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -136,9 +136,12 @@ public class Cocos2dxHelper { parameters = new Object[]{Cocos2dxReflectionHelper.getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_FRAMES_PER_BUFFER")}; final String strBufferSizeInFrames = Cocos2dxReflectionHelper.invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters); - sampleRate = Integer.parseInt(strSampleRate); - bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames); - + try { + sampleRate = Integer.parseInt(strSampleRate); + bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames); + } catch (NumberFormatException e) { + Log.e(TAG, "parseInt failed", e); + } Log.d(TAG, "sampleRate: " + sampleRate + ", framesPerBuffer: " + bufferSizeInFrames); } else { Log.d(TAG, "android version is lower than 17");