3
我想在設備引導完成時顯示警報對話框。廣播接收機沒有問題,它工作正常。但是啓動完成後,沒有任何公開活動,因此我在此處獲得NullPointerException
。如何在這種情況下顯示對話框?這是我用來顯示對話框的代碼:BOOT_COMPLETED後的警報對話框中的空指針異常
public class RestartReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
AlertDialog alertHelp;
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
TextView m_timetext = new TextView(context);
m_timetext.setText("hello");
// m_timetext.setTextColor(getResources().getColor(R.color.dark_green));
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
linearLayout.setOrientation(1);
linearLayout.addView(m_timetext);
dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
alertHelp = dialog.create();
alertHelp.setView(linearLayout);
alertHelp.show();
Log.d("In","Switched On");
}
}
請幫助我。提前致謝。
請幫幫我。 – user1726619
哪一行給你空指針? – Carnal
alertHelp.show() - >這裏我得到異常先生。 – user1726619