gpt4 book ai didi

java - addParentStack 中的 NameNotFoundException

转载 作者:行者123 更新时间:2023-11-29 19:44:33 25 4
gpt4 key购买 nike

我正在尝试构建一个通知并显示它,还为我正在显示的 Intent 构建一个堆栈。但是我得到一个 NameNotFoundException。

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());

这是我得到的异常。

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)

我检查了包名称和放置类 ForecastFragment 的包,但它们都是正确的。有人可以帮我整理一下吗。

最佳答案

fragment 不是组件,不能与 Intent 一起使用。只有 ActivityServiceBroadcastReceiver 等组件可用于构建 Intent

因此,您的第一行 (new Intent(mContext, ForecaseFragment.class)) 和 addParentStack(ForecastFragment.class) 都是无效的。您需要使用在包含该 fragment 的 list 中注册的 Activity

关于java - addParentStack 中的 NameNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38043592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com