2014-10-17 156 views
0

下面是代码我怎么能打开浏览器onPostExecute

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); 

Thisthis不起作用为了我。 我能做什么?

回答

0

为什么不直接从Fragment调用getActivity(),然后像调用getActivity()一样调用startActivity()。startActivity(intent);

0

从例外情况来看,您看起来像在一个片段上调用了这个方法,该片段还没有(还没有?)附加到一个Activity上。从Fragment类的源:

public void startActivity(Intent intent, Bundle options) { 
    if (mActivity == null) { 
     throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 
    } 
    ... 

为了解决这个问题,只是改变在那里调用此方法的地方,即onAttach()之后和之前onDetach()