Java 如何在PostExecute上打开浏览器
这是密码Java 如何在PostExecute上打开浏览器,java,android,Java,Android,这是密码 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.androi
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);
对我来说不管用。
我能做什么?从异常情况看,您似乎正在对一个尚未调用的片段调用此方法?附属于某项活动的。从片段类的源:
要解决此问题,只需更改调用此方法的位置,即在onAttach之后和onDetach之前。为什么不从片段中调用getActivity,然后像getActivity.StartActivityContent那样调用startActivity
public void startActivity(Intent intent, Bundle options) {
if (mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
...