Android java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxx.MainActivity}: java.lang.NullPointerException

FATAL EXCEPTION: main
java.lang.Error: FATAL EXCEPTION [main]
Unity version     : 4.1.2f1
Device model      : Acer A500
Device fingerprint: acer/a500_ww_cus1/picasso:4.0.3/IML74K/1336617649:user/release-keys
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.gcm/com.test.gcm.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.unity3d.player.g.a(Unknown Source)
at com.unity3d.player.g.b(Unknown Source)
at com.unity3d.player.UnityPlayer.resume(Unknown Source)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer.init(Unknown Source)
at com.unity3d.player.UnityPlayerActivity.onCreate(Unknown Source)
at com.test.gcm.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more

 유니티3D 안드로이드에 푸시된 Notification을 클릭해서 Activity를 실행하려고 GCM 연동중에 위와 같은 에러가 발생했습니다.

Intent notificationIntent = new Intent(arg0, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(arg0, 0 , notificationIntent, 0);

 붉은색 부분이 문제였습니다. 그래도 이미 실행중인 앱을 죽이고 푸시를 클릭해 새로 Activity가 생성이 되는 건 잘됩니다. 앱이 실행중인 상태에서는 저런 에러가 발생하네요.

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP

| Intent.FLAG_ACTIVITY_SINGLE_TOP);

 플래그 값을 위와 같이 변경해줍니다. 그러면 새로 실행이든 실행중인거 포그라운드로 호출하든 잘 되네요.

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.