我有一个音乐播放器以前运行正常。但是,现在升级后,每次我将一个简单的项添加到布局中,如下所示。当我尝试播放歌曲时应用程序会崩溃。我必须清理项目并重新运行,它会起作用。重新运行后,我删除了代码,当我尝试播放时它会再次崩溃。然后我需要再次清理项目才能再次工作。
<Button android:id="@+id/btnTest"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="This is a test"
android:layout_marginLeft="15dp"
android:layout_below="@+id/btnTest2"
/>
我尝试与gradle文件同步但它不起作用。 我得到的错误是
致命的例外:主要 过程:com.musicplayer,PID:30487 android.app.RemoteServiceException:从com.musicplayer包发布的错误通知:无法展开RemoteViews:StatusBarNotification(pkg = com.musicplayer user = UserHandle {0} id = 11 tag = null score = 0 key = 0 | com.musicplayer | 11 | null | 10506:通知(pri = 0 contentView = com.musicplayer / 0x7f040039 vibrate = null sound = null defaults = 0x20 flags = 0x2 color = 0x00000000 vis = PRIVATE)) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1466) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:135) 在android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) 在java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
这是我的远程通知方法
public void showNotification() {
PendingIntent pendingIntent;
Intent intent;
notificationView.setTextViewText(R.id.notify_song_name, mListSongs.get(SONG_POS).getSongName());
intent = new Intent(ACTION_STOP);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_STOP, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_stop, pendingIntent);
intent = new Intent(ACTION_PREVIOUS);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PREVIOUS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_previous, pendingIntent);
intent = new Intent(ACTION_NEXT);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_NEXT, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_next, pendingIntent);
intent = new Intent(ACTION_PAUSE);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PAUSE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_pause, pendingIntent);
intent = new Intent(ACTION_PLAY);
pendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_CODE_PLAY, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.notify_btn_play, pendingIntent);
intent = new Intent(this, MusicPlayerActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
pendingIntent = PendingIntent.getActivity(this, 0,intent, 0);
mNotification = notificationBuilder
.setSmallIcon(R.drawable.app_icon).setOngoing(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setContent(notificationView)
.setDefaults(Notification.FLAG_NO_CLEAR)
.build();
notificationManager.notify(NOTIFICATION_ID, mNotification);
}