i try to open an url form a dialog class. I tried it with following code, but I get a NullPointerException. How can I do this?
I start the Dialog with following from my Activity:
AboutDialog about = new AboutDialog(this);
about.setTitle(R.string.Text_about);
about.show();
This is the Dialog class:
public class AboutDialog extends Dialog implements OnClickListener{
private Button button_ok;
.
.
.
}
public void onClick(View arg0) {
myActivity activity = new myActivity();
String url = "http://www.test.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
activity.startActivity(i);
}
You are creating a new Activity in the onCick method. Activities should not be created manually. They are set up from the system. I would guess that the Activity is not set up properly and this results in the NullPointerException.
You should get a valid context through getContext. Use
instead of