Reputation: 218
I have some data in listview from list view I want to send my one field to dialogbox
l=(ListView) findViewById(android.R.id.list);
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3) {
TextView textView = (TextView) v.findViewById(R.id.name);
String text = textView.getText().toString();
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.customdailog);
dialog.setTitle("Fill This Form");
// set the custom dialog components - text, image and button
EditText DrName,Patient_mobile,Username;
DrName=(EditText)findViewById(R.id.DortorName);
DrName.setHint("sss");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialog.show();
my log cat
FATAL EXCEPTION: main java.lang.NullPointerException at com.example.finddoctor.Doctor_Names$2.onItemClick(Doctor_Names.java:128) at android.widget.AdapterView.performItemClick(AdapterView.java:284) at android.widget.ListView.performItemClick(ListView.java:3513) at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 111
Reputation: 14408
It seems that EditText DrName
is part of dialog and you are accessing it from activity layout so it gives null pointer exception,therefore
Change
DrName=(EditText)findViewById(R.id.DortorName);
to
DrName=(EditText) dialog.findViewById(R.id.DortorName);
Upvotes: 0