我得到以下 Stacktrack 并且似乎无法解决。SherlockFragment
我使用以下代码向另一个发送字符串。
发送意图
@Override
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
if (url.contains("google.com")
|| url.contains("google.com/images")) {
Log.i("WebView",
"URL is part of the MainActiviy" + "URL = " + url);
view.loadUrl(url);
progressBar.setVisibility(View.VISIBLE);
} else {
Log.i("WebView",
"URL is not part of MainActivity" + "URL = " + url);
Intent settings = new Intent();
settings.setClassName("org.example.code",
"org.example.code.FullBrowser");
settings.putExtra("url", url);
startActivity(settings);
}
return true;
}
接收意图
WebView web;
String url;
static ProgressBar progressBar;
@Override
public View onCreateView(LayoutInflater inf, ViewGroup grp, Bundle icicle) {
View v = inf.inflate(R.layout.activity_main, grp, false);
web = (WebView) v.findViewById(R.id.webView);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
setHasOptionsMenu(true);
return v;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle extras = getActivity().getIntent().getExtras();
url = extras.getString("url");
web.loadUrl(url);
}
建议更改
url = extras.getString("url");
Bundle arguments = new Bundle(); arguments.putString("url", url);
FullBrowser fragment = new FullBrowser(); fragment.setArguments(arguments);
getFragmentManager().beginTransaction().replace(R.id.webView, fragment).commit();
web.loadUrl(url);
还是给我下面的~
日志猫
06-09 23:15:24.403: E/AndroidRuntime(8574): FATAL EXCEPTION: main
06-09 23:15:24.403: E/AndroidRuntime(8574): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.example.code/org.example.code.FullBrowser}: java.lang.ClassCastException: org.example.code.FullBrowser cannot be cast to android.app.Activity
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread.access$700(ActivityThread.java:151)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.os.Looper.loop(Looper.java:137)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread.main(ActivityThread.java:5293)
06-09 23:15:24.403: E/AndroidRuntime(8574): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 23:15:24.403: E/AndroidRuntime(8574): at java.lang.reflect.Method.invoke(Method.java:511)
06-09 23:15:24.403: E/AndroidRuntime(8574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-09 23:15:24.403: E/AndroidRuntime(8574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-09 23:15:24.403: E/AndroidRuntime(8574): at dalvik.system.NativeStart.main(Native Method)
06-09 23:15:24.403: E/AndroidRuntime(8574): Caused by: java.lang.ClassCastException: org.example.code.FullBrowser cannot be cast to android.app.Activity
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
06-09 23:15:24.403: E/AndroidRuntime(8574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)