好的,当我单击按钮启动另一个片段时,我一直收到此错误..
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: 错误/AndroidRuntime(7816): 在 android.app.Instrumentation.newActivity(Instrumentation.java:1022) 07-30 20:54:05.950: 错误/AndroidRuntime(7816): 在 android. app.ActivityThread.performLaunchActivity(ActivityThread.java:1663)
这是我正在尝试做的事情,当从这个活动中单击按钮 findIt 时..
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)findViewById(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);
}
});
}
我正在将另一个这个片段发射到视图中......
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);
}
}
这使用我在设置第一个活动的相同 xml 中设置的浏览器来启动 webbrowser 并在我设置的片段中查找 URL。
它从我创建的 webview 布局中获取 loadUrl() 中的浏览器并将其膨胀到片段中。但我不断收到上面的错误。