2016-06-26 18 views
1

Ich versuche, eine Benachrichtigung zu erstellen und anzuzeigen und auch einen Stapel zu der Absicht zu erstellen, die ich anzeigen. Aber ich bekomme eine NameNotFoundException.NameNotFoundException in addParentStack

Intent resultIntent = new Intent(mContext, ForecastFragment.class); 

TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); 
stackBuilder.addParentStack(ForecastFragment.class); 
stackBuilder.addNextIntent(resultIntent); 
PendingIntent resultPendingIntent = stackBuilder. 
        getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 
mBuilder.setContentIntent(resultPendingIntent); 
NotificationManager notificationManager = 
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.notify(10 ,mBuilder.build()); 

Hier ist die Ausnahme, die ich bekomme.

3541-3562/com.example.android.sunshine.app E/AndroidRuntime: FATAL EXCEPTION: SyncAdapterThread-1 
      Process: com.example.android.sunshine.app, PID: 3541 
      java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.android.sunshine.app/com.example.android.sunshine.app.ForecastFragment} 
      at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:247) 
      at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:226) 
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.notifyWeather(SunshineSyncAdapter.java:526) 
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.getWeatherDataFromJson(SunshineSyncAdapter.java:424) 
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.onPerformSync(SunshineSyncAdapter.java:255) 
      at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259) 
      Caused by: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.android.sunshine.app/com.example.android.sunshine.app.ForecastFragment} 
      at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:314) 
      at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:301) 
      at android.support.v4.app.NavUtils.getParentActivityIntent(NavUtils.java:256) 
      at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:240) 
      at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:226)  
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.notifyWeather(SunshineSyncAdapter.java:526)  
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.getWeatherDataFromJson(SunshineSyncAdapter.java:424)  
      at com.example.android.sunshine.app.sync.SunshineSyncAdapter.onPerformSync(SunshineSyncAdapter.java:255)  
      at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259) 

überprüfte ich den Paketnamen und das Paket, in dem die Klasse ForecastFragment platziert ist, aber es ist alles in Ordnung. Kann mir bitte jemand helfen, diesen zu sortieren.

Antwort

2

Fragmente sind keine Komponente und können nicht mit Intents verwendet werden. Nur Komponenten wie Activity, Service oder BroadcastReceiver können verwendet werden, um eine Intent zu erstellen.

Daher sind Ihre erste Zeile (new Intent(mContext, ForecaseFragment.class)) und addParentStack(ForecastFragment.class) beide ungültig. Sie müssen das Activity verwenden, das in dem Manifest registriert ist, das das Fragment enthält.

+0

Danke, das hat mein Problem behoben. –