我的要求是单击图像,我应该通过 alertbuilder 发出警报。它发生得非常好。在警报构建器中,我指的是一个布局。然后我指的是小部件的 id。然后在 onclick 方法的这个范围内,我正在为这些小部件执行操作。
holder.source.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Source",Toast.LENGTH_LONG).show();
dialog = new Dialog(RecordingActivity2.this);
dialog.setTitle("Source File");
dialog.setContentView(R.layout.activity_read);
ImageButton im = (ImageButton)findViewById(R.id.close);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
**If i am making actions here application is closing unexpectedly.**
}
});
dialog.show();
}
});
这是我的 logcat 输出
07-04 17:25:29.923: E/AndroidRuntime(1928): FATAL EXCEPTION: main
07-04 17:25:29.923: E/AndroidRuntime(1928): java.lang.NullPointerException
07-04 17:25:29.923: E/AndroidRuntime(1928): at com.pdev.activities.RecordingActivity2$VehicleAdapter$1.onClick(RecordingActivity2.java:209)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.view.View.performClick(View.java:3480)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.view.View$PerformClick.run(View.java:13983)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.os.Handler.handleCallback(Handler.java:605)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.os.Handler.dispatchMessage(Handler.java:92)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.os.Looper.loop(Looper.java:137)
07-04 17:25:29.923: E/AndroidRuntime(1928): at android.app.ActivityThread.main(ActivityThread.java:4340)