Note that there are some explanatory texts on larger screens.

plurals
  1. POSending String through Intent between two SherlockFragments
    text
    copied!<p>Im getting the following Stacktrack and cant seem how to resolve. Im sending a string to another <code>SherlockFragment</code> with the following code .</p> <h2>Sending Intent</h2> <pre><code> @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; } </code></pre> <h2>Receiving Intent</h2> <pre><code>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); } </code></pre> <h2>Recommended Change</h2> <pre><code>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); </code></pre> <p>Still giving me the following~</p> <h2>LogCat</h2> <pre><code>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) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload