Reputation: 203
My requirement is on the click of a image i should give an alert by alertbuilder. It is happening perfectly fine.In the alertbuilder i am referring one layout.Then i am referring the ids of widgets.Then within this scope of onclick method iam making actions for these widgets.
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();
}
});
Here is my logcat output
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)
Upvotes: 0
Views: 91
Reputation: 943
Replace
ImageButton im = (ImageButton)findViewById(R.id.close);
To
ImageButton im = (ImageButton)dialog.findViewById(R.id.close);
Upvotes: 5