Resources$NotFoundException: String resource ID #0x0
See original GitHub issue[READ] Step 1: Are you in the right place?
Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:
- For general technical questions, post a question on StackOverflow with the firebase tag.
- For general Firebase discussion, use the firebase-talk google group.
- For help troubleshooting your application that does not fall under one of the above categories, reach out to the personalized Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Android Studio version: 3.5.3
- Firebase Component: FCM
- Component version: 17.2.1
[REQUIRED] Step 3: Describe the problem
after updating to androidx and new FCM version, I got a new exception on push notification.
Fatal Exception: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText + 363(Resources.java:363)
at android.content.res.Resources.getString + 456(Resources.java:456)
at android.content.Context.getString + 580(Context.java:580)
at com.google.firebase.messaging.zzb.zzb + 234(zzb.java:234)
at com.google.firebase.messaging.zzb.zza + 6(zzb.java:6)
at com.google.firebase.messaging.zzd.zza + 33(zzd.java:33)
at com.google.firebase.messaging.FirebaseMessagingService.zzc + 69(FirebaseMessagingService.java:69)
at com.google.firebase.messaging.zze.run + 2(zze.java:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run + 6(zza.java:6)
at java.lang.Thread.run + 764(Thread.java:764)
Steps to reproduce:
just send push notification to Samsung or Huawei devices with android 8-9
Relevant Code:
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.3.0'
implementation 'com.google.android.gms:play-services-measurement-api:17.2.1'
implementation 'com.google.android.gms:play-services-measurement-base:17.2.1'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-iid:20.0.2'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String NOTIFICATION_CHANNEL_ID = "...";
private static final String NOTIFICATION_CHANNEL_NAME = "...";
private static final String NOTIFICATION_CHANNEL_DESC = "...";
@Override
public void onNewToken(String token) {
try {
saveToken(token);
} catch (Exception e) {
e.printStackTrace();
}
FirebaseMessaging.getInstance().subscribeToTopic("...");
FirebaseMessaging.getInstance().subscribeToTopic("version" + Build.VERSION.RELEASE);
}
private void saveToken(String token) throws Exception {
...
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
showNotification(remoteMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
private void showNotification(RemoteMessage remoteMessage) throws Exception {
NotificationManager notificationManager = (NotificationManager) App.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(NOTIFICATION_CHANNEL_DESC);
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder b = new NotificationCompat.Builder(App.getContext(), NOTIFICATION_CHANNEL_ID);
if (String.valueOf(remoteMessage.getData().get("targetId")).equals("128")) {
Logger.e("LastIdddd", "showNotification: " + remoteMessage.getData().get("entityId"));
if (Dao.getInstance().Preferences.getString(Preferenses.ReceiptNotificationLastID, "").equals("0") ||
Dao.getInstance().Preferences.getString(Preferenses.ReceiptNotificationLastID, "").equals("") ||
Dao.getInstance().Preferences.getString(Preferenses.ReceiptNotificationLastID, "") == null) {
Dao.getInstance().Preferences.setString(Preferenses.ReceiptNotificationLastID, remoteMessage.getData().get("entityId"));
Logger.e("LastId", "showNotification: " + remoteMessage.getData().get("entityId"));
}
int notificationCount = Dao.getInstance().Preferences.getInteger(Preferenses.ReceiptNotificationCount, 0);
notificationCount++;
Dao.getInstance().Preferences.setInteger(Preferenses.ReceiptNotificationCount, notificationCount);
b.setContentText("شما " + notificationCount + " پیام خوانده نشده دارید");
b.setStyle(new NotificationCompat.BigTextStyle(b)
.bigText("شما " + notificationCount + " پیام خوانده نشده دارید\n" + remoteMessage.getData().get("body"))
.setBigContentTitle(remoteMessage.getData().get("title"))
.setSummaryText("You have " + notificationCount + " Notifications")
);
b.setContentTitle(remoteMessage.getData().get("title"));
b.setContentText(remoteMessage.getData().get("body"));
Intent intent = new Intent(App.getContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("isNotif", "true");
intent.putExtra("targetId", String.valueOf(remoteMessage.getData().get("targetId")));
intent.putExtra("entityId", String.valueOf(remoteMessage.getData().get("entityId")));
intent.putExtra("popup", String.valueOf(remoteMessage.getData().get("popup")));
intent.putExtra("popup_title", String.valueOf(remoteMessage.getData().get("popup_title")));
intent.putExtra("popup_text", String.valueOf(remoteMessage.getData().get("popup_text")));
intent.putExtra("url", String.valueOf(remoteMessage.getData().get("url")));
PendingIntent contentIntent = PendingIntent.getActivity(App.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_statusbar)
.setColor(ContextCompat.getColor(this, R.color.orange));
if (remoteMessage.getData() != null) {
b.setContentIntent(contentIntent);
}
notificationManager.notify(2, b.build());
} else {
b.setContentTitle(remoteMessage.getNotification().getTitle());
b.setContentText(remoteMessage.getNotification().getBody());
Intent intent = new Intent(App.getContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("isNotif", "true");
intent.putExtra("targetId", String.valueOf(remoteMessage.getData().get("targetId")));
intent.putExtra("entityId", String.valueOf(remoteMessage.getData().get("entityId")));
intent.putExtra("popup", String.valueOf(remoteMessage.getData().get("popup")));
intent.putExtra("popup_title", String.valueOf(remoteMessage.getData().get("popup_title")));
intent.putExtra("popup_text", String.valueOf(remoteMessage.getData().get("popup_text")));
intent.putExtra("url", String.valueOf(remoteMessage.getData().get("url")));
intent.putExtra(KEY_ID_INSTITUTE, String.valueOf(remoteMessage.getData().get(KEY_ID_INSTITUTE)));
intent.putExtra(KEY_PRICE, String.valueOf(remoteMessage.getData().get(KEY_PRICE)));
PendingIntent contentIntent = PendingIntent.getActivity(App.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_statusbar)
.setColor(ContextCompat.getColor(this, R.color.orange));
if (remoteMessage.getData() != null) {
b.setContentIntent(contentIntent);
}
notificationManager.notify(1, b.build());
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
android.content.res.Resources$NotFoundException: String ...
If you pass it an integer it will try to look for the corresponding string resource id - which it can't find, which...
Read more >android.content.res.Resources$NotFoundException: String ...
Resources $NotFoundException: String resource ID #0x0. The app is crashing when I try to run it. I think this issue has something to...
Read more >Java - String resource ID #0x0 – iTecNote
Resources $NotFoundException: String resource ID #0x0. androidjavalistviewxml. I'm developing an Android app which reads data from MySQL database and I faced ...
Read more >String resource ID #0x0 - jiduoduo - 博客园
解决: 这种情况一般不是因为没有id的问题,是因为将一个int的值,赋给了setText之类的。 系统将这个值认为是id了,导致layout中出错。
Read more >android.content.res.Resources$NotFoundException - B4X
Android Question android.content.res.Resources$NotFoundException: String resource ID #0x0 · TIMX · Erel.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Duplicate of #1313
Closing as duplicate, feel free to re-open if necessary