2013-01-09 99 views
-2

我開發了一個應用程序並實現了GCM(Google Cloud Messaging),它在模擬器上以及在bluestacks上都能很好地工作,但是當我在設備上運行它時,不幸的是,我無法得到原因。GCM應用程序在模擬器上正常工作,但在Android設備上崩潰

Manifest file 

<uses-sdk android:minSdkVersion="8" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.androiddemos.NotificationActivity" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".ResultActivity" 
     android:parentActivityName=".MainActivity" > 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value=".NotificationActivity" /> 
    </activity> 
    <activity 
     android:name=".GcmActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver 
     android:name="com.google.android.gcm.GCMBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 

      <category android:name="com.example.androiddemos" /> 
     </intent-filter> 
    </receiver> 

    <service android:name=".GCMIntentService" > 
    </service> 
</application> 

<permission 
    android:name="com.example.androiddemos.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" > 
</permission> 
<!-- App receives GCM messages. --> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<!-- GCM connects to Google Services. --> 
<uses-permission android:name="android.permission.INTERNET" /> 
<!-- GCM requires a Google account. --> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<!-- Keeps the processor from sleeping when a message is received. --> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="com.example.androiddemos.permission.C2D_MESSAGE" /> 

logcat的 01-09 14:55:27.034: E/AndroidRuntime(25344): java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity} 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:236) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:215) 01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity.sendNotification(GcmActivity.java:70) 01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity.checkGCM(GcmActivity.java:49) 01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity$1.onClick(GcmActivity.java:33) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.view.View.performClick(View.java:4084) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.view.View$PerformClick.run(View.java:16966) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Handler.handleCallback(Handler.java:615) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Handler.dispatchMessage(Handler.java:92) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Looper.loop(Looper.java:137) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.app.ActivityThread.main(ActivityThread.java:4745) 01-09 14:55:27.034: E/AndroidRuntime(25344): at java.lang.reflect.Method.invokeNative(Native Method) 01-09 14:55:27.034: E/AndroidRuntime(25344): at java.lang.reflect.Method.invoke(Method.java:511) 01-09 14:55:27.034: E/AndroidRuntime(25344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 01-09 14:55:27.034: E/AndroidRuntime(25344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 01-09 14:55:27.034: E/AndroidRuntime(25344): at dalvik.system.NativeStart.main(Native Method) 01-09 14:55:27.034: E/AndroidRuntime(25344): Caused by: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity} 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:225) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:298) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.NavUtils.getParentActivityIntent(NavUtils.java:261) 01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:229) 01-09 14:55:27.034: E/AndroidRuntime(25344): ... 15 more

+0

無論是如果您不提供更多詳細信息,請聯繫我們 – Henry

+0

您需要什麼細節,完整的代碼或清單代碼 –

+0

logcat輸出和相關的代碼。 – Henry

回答

3

我相信這個問題是因爲你沒有在你的清單中定義MainActivity在此基礎上的logcat行:

14:55:27.034: E/AndroidRuntime(25344): Caused by: 
android.content.pm.PackageManager$NameNotFoundException: 
ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity} 01-09 

你MainActivity引用作爲parentActivityName但在清單中根本沒有定義:

<activity 
    android:name=".ResultActivity" 
    android:parentActivityName=".MainActivity" > 
    <meta-data 
     android:name="android.support.PARENT_ACTIVITY" 
     android:value=".NotificationActivity" /> 
</activity> 

如果你還在使用MainActivity你需要將它添加到清單:

<activity 
    android:name=".MainActivity"> 
</activity> 
相關問題