开发者

Fragment Activity cannot be cast to app.Activity.

Okay i keep getting this error when i have a button click launch another Fragment..

07-30 20:54:05.950: ERROR/AndroidRuntime(7816): Caused by: java.lang.ClassCastException: com.fttech.gameIT.shopping_details_fragment cannot be cast to android.app.Activity

07-30 20:54:05.950: ERROR/AndroidRuntime(7816): at android.app.Instrumentation.newActivity(Instrumentation.java:1022) 07-30 20:54:05.950: ERROR/AndroidRuntime(7816): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663)

Here is what i am trying to do, when the button findIt is clicked from this activity..

  public class shoppingClass extends FragmentActivity{
Button findIT;
EditText game;
String item = null;
WebView browser;
RadioGroup site;
RadioGroup type;
String url;
String console;
shopping_details_fragment shopping;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shopping);

    findIT = (Button)findViewByI开发者_开发百科d(R.id.findIT);
    shop = (EditText)findViewById(R.id.item);
    type = (RadioGroup)findViewById(R.id.console);
    site = (RadioGroup)findViewById(R.id.shopping_group);

    final Intent d = new Intent(this, shopping_details_fragment.class);
    findIT.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getUserPreference();
            shopping.loadUrl(url);
            startActivity(d);


        }
    });

  }

I am launching another this Fragment into the view...

public class shopping_details_fragment extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

    //Return the view for our WebView
    return(inflater.inflate(R.id.browserFrag,container, false));

}

public void loadUrl(String url){
    ((WebView)getView().findViewById(R.id.browser)).loadUrl(url);
}

}

This uses the browser i have set up in the same xml that the first activitiy is set up in to launch a webbrowser and look up a URL in a fragment i have set..

Its getting the browser in loadUrl() from a webview layout i created and inflating it into the fragment. But i keep getting the error above.


Fragment and Activity aren't directly related like that, you can't just cast between them. Use the getActivity() method on the fragment instead, to return its activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜