2013-03-08 1 views
0

나는 내 코드에서 널 포인트 오류가 오전 로그는 로그 캣 파일이 방법Android 코드에서 널 포인터 오류가 발생하는 이유는 무엇입니까?

/** 
* Returns the current SKUs owned by the user of the type and package name specified along with 
* purchase information and a signature of the data to be validated. 
* This will return all SKUs that have been purchased in V3 and managed items purchased using 
* V1 and V2 that have not been consumed. 
* @param apiVersion billing API version that the app is using 
* @param packageName package name of the calling app 
* @param type the type of the in-app items being requested 
*  ("inapp" for one-time purchases and "subs" for subscription). 
* @param continuationToken to be set as null for the first call, if the number of owned 
*  skus are too many, a continuationToken is returned in the response bundle. 
*  This method can be called again with the continuation token to get the next set of 
*  owned skus. 
* @return Bundle containing the following key-value pairs 
*   "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on 
*    failure as listed above. 
*   "INAPP_PURCHASE_ITEM_LIST" - StringArrayList containing the list of SKUs 
*   "INAPP_PURCHASE_DATA_LIST" - StringArrayList containing the purchase information 
*   "INAPP_DATA_SIGNATURE_LIST"- StringArrayList containing the signatures 
*          of the purchase information 
*   "INAPP_CONTINUATION_TOKEN" - String containing a continuation token for the 
*          next set of in-app purchases. Only set if the 
*          user has more owned skus than the current list. 
*/ 
Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken); 

에 대한

03-08 13:24:45.619: E/AndroidRuntime(7149): FATAL EXCEPTION: main 
03-08 13:24:45.619: E/AndroidRuntime(7149): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.imobilize.ETV_V3_INAPP_SUB/com.imobilize.ETV_V3_INAPP_SUB.IntroBLevActivity}: java.lang.NullPointerException 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.ActivityThread.access$600(ActivityThread.java:128) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.os.Handler.dispatchMessage(Handler.java:99) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.os.Looper.loop(Looper.java:137) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.ActivityThread.main(ActivityThread.java:4517) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at java.lang.reflect.Method.invokeNative(Native Method) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at java.lang.reflect.Method.invoke(Method.java:511) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at dalvik.system.NativeStart.main(Native Method) 
03-08 13:24:45.619: E/AndroidRuntime(7149): Caused by: java.lang.NullPointerException 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at com.imobilize.ETV_V3_INAPP_SUB.IntroBLevActivity.getPurchasedSubs(IntroBLevActivity.java:200) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at com.imobilize.ETV_V3_INAPP_SUB.IntroBLevActivity.checkValidation(IntroBLevActivity.java:238) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at com.imobilize.ETV_V3_INAPP_SUB.IntroBLevActivity.onCreate(IntroBLevActivity.java:96) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.Activity.performCreate(Activity.java:4470) 
03-08 13:24:45.619: E/AndroidRuntime(7149):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053) 

SPECS 덤프 여기에 여기에

199  public void getPurchasedSubs() throws RemoteException { 
200   Bundle ownedItems = mService.getPurchases(3, getPackageName(), "subs", null); 

을 가리키는 다시 유효하게 된 패키지 이름을 확인합니다.

그녀 e는 mService가 생성 된 코드입니다. IInAppBillingService mService;

ServiceConnection mServiceConn = new ServiceConnection() { 
    //@Overide 
     public void onServiceDisconnected(ComponentName name) { 
     mService = null; 
    } 
     //@Overide 
    public void onServiceConnected(ComponentName name, 
     IBinder service) { 
     mService = IInAppBillingService.Stub.asInterface(service); 
    } 

}; 

logcat 파일을 해석하는 데 그리 좋지가 않아서 대답이 내 앞에있을 수 있습니다.

나는이 코드를 열어서 mService를 언제든지 사용할 수 있다고 생각했습니다.

 bindService(new 
      Intent("com.android.vending.billing.InAppBillingService.BIND"), 
        mServiceConn, Context.BIND_AUTO_CREATE); 
+2

중단 점을 사용하고 코드를 실행 해 보았습니까? getPurchases()를 호출하려고하면 mService가 null 인 것 같습니다. – crazylpfan

+0

onServiceDisconnected에 로그를 추가하고 코드를 실행하기 전에 연결이 끊어 졌는지 확인하십시오. 예외 문 앞에 Null check를 추가하고 Null인지 확인하기 위해 기록합니다. 이 코드를 실행할 때 서비스가 연결되지 않았거나이 코드를 실행할 때 연결이 끊어지는 것 같습니다. – anargund

+0

NPE는 어떤 라인을 유발합니까? (ActivityThread.java:1970) –

답변

4

서비스에 연결하기 전에 mService을 사용한다고 생각합니다. 이 당신을 도와

ServiceConnection mServiceConn = new ServiceConnection() { 
    public void onServiceDisconnected(ComponentName name) { 
     mService = null; 
    } 

    public void onServiceConnected(ComponentName name, 
     IBinder service) { 
     mService = IInAppBillingService.Stub.asInterface(service); 
getPurchasedSubs(); 
    } 

}; 

희망을 :

내 제안 활동이 서비스 여부, 또는 다음과 같이 onServiceConnectedgetPurchasedSubs()를 사용하여 연결 여부를 확인하기 위해 부울 변수를 사용하는 것입니다.

+0

어떻게하면 PurchasedSubs()를 얻을 수 있습니까? 언제든지 사용할 수 있습니다. 이 사용할 수 있도록해야했다 내 onCreate 한 조각을 추가하지만 그것은 작동하지 않는 이유 중 일부입니다. –

+0

또한 나는 이상한 오류가 나는 그것이 필요하다고 말한 MServiceeConn의 전반적인 부분을 다룰 때 얻습니다. 수퍼 클래스 메서드를 무시해야하므로 제거해야합니다. 그게 나쁜 영향을 미칠 수 있습니까? –

+0

PurchasedSubs()를 사용할 수 있습니다. 언제든지 원할 수 있지만 서비스에 연결 한 후에해야합니다. 또한 bindService (...); onStart()에서 onCreate가 실행되기 전에 바인딩합니다. 이 링크도 참조하십시오 [--- link ---] (http://dharmendra4android.blogspot.com/2012/05/bind-service-using-ibinder-class.html) – AwadKab

관련 문제