这是代码
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(this.redirectUrl+"?username="+getValue(loginString)+"&password="+getValue(pwdString)));
startActivity(browserIntent);
我有这个错误:
10-17 15:30:35.288 5467-5467/com.example.android.navigationdrawerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40cd7930)
10-17 15:30:35.298 5467-5467/com.example.android.navigationdrawerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Fragment PlanetFragment{41b91f78} not attached to Activity
在这一行:
startActivity(browserIntent);
答案 0 :(得分:0)
从例外情况看,你看起来像是在一个没有(但是?)附加到Activity的Fragment上调用这个方法。来自Fragment
类的来源:
public void startActivity(Intent intent, Bundle options) {
if (mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
...
要解决此问题,只需更改调用此方法的位置,即在onAttach()
之后和onDetach()
之前。
答案 1 :(得分:0)
为什么不从Fragment调用getActivity(),然后像getActivity()一样调用startActivity()。startActivity(intent);