Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Onclick按钮使应用程序崩溃_Java_Android_Eclipse - Fatal编程技术网

Java Onclick按钮使应用程序崩溃

Java Onclick按钮使应用程序崩溃,java,android,eclipse,Java,Android,Eclipse,我添加了一个按钮,当用户单击该按钮时,该按钮将返回主屏幕,但是每次单击该按钮时,应用程序都会强制关闭 我想你正在获得NPE PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); <<<<Error is here NPE Intent intent = new Intent(); Intent intent=new Intent(Intent.ACTION_MAIN); homeI

我添加了一个按钮,当用户单击该按钮时,该按钮将返回主屏幕,但是每次单击该按钮时,应用程序都会强制关闭


我想你正在获得NPE

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);  <<<<Error is here NPE

Intent intent = new Intent();
Intent intent=new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);  <<<There must be Compile time error because you did not declare homeIntent
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);

pendingent-pIntent=pendingent.getActivity(this,0,intent,0) 就我所见,我认为你的问题在这里:

public void onClick(View v) {
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("Ticker Title")
.setContentTitle("Content Title")
.setContentText("Notifcation Content")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);


Intent intent = new Intent();
Intent intent=new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
}
更准确地说,这一行的意图是:

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
在实际创建之前,您正试图将此意图添加到
pendingent


您正在使用的
homeIntent
是什么?

发布日志跟踪,并在问题中内联发布代码的相关部分。