无法从我的应用程序启动浏览器

时间:2012-08-26 16:18:05

标签: android url browser

当我使用这段代码时:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
startActivity(browserIntent);

我收到以下错误消息:

08-26 18:14:35.305: E/AndroidRuntime(9427): FATAL EXCEPTION: main
08-26 18:14:35.305: E/AndroidRuntime(9427): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = dev.socialnet.server.Server)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Looper.loop(Looper.java:130)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread.main(ActivityThread.java:3691)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.reflect.Method.invoke(Method.java:507)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at dalvik.system.NativeStart.main(Native Method)
08-26 18:14:35.305: E/AndroidRuntime(9427): Caused by: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = dev.socialnet.server.Server)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Parcel.readSerializable(Parcel.java:2026)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Parcel.readValue(Parcel.java:1897)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Parcel.readMapInternal(Parcel.java:2083)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Bundle.unparcel(Bundle.java:208)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Bundle.getBundle(Bundle.java:1078)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.content.Intent.getBundleExtra(Intent.java:3843)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at com.android.browser.BrowserActivity.handleWebSearchIntent(BrowserActivity.java:1463)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at com.android.browser.BrowserActivity.onCreate(BrowserActivity.java:488)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-26 18:14:35.305: E/AndroidRuntime(9427):     ... 11 more
08-26 18:14:35.305: E/AndroidRuntime(9427): Caused by: java.lang.ClassNotFoundException: dev.socialnet.server.Server
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.Class.classForName(Native Method)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.Class.forName(Class.java:234)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2564)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1823)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:811)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2039)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at android.os.Parcel.readSerializable(Parcel.java:2020)
08-26 18:14:35.305: E/AndroidRuntime(9427):     ... 20 more
08-26 18:14:35.305: E/AndroidRuntime(9427): Caused by: java.lang.NoClassDefFoundError: dev.socialnet.server.Server
08-26 18:14:35.305: E/AndroidRuntime(9427):     ... 30 more
08-26 18:14:35.305: E/AndroidRuntime(9427): Caused by: java.lang.ClassNotFoundException: dev.socialnet.server.Server in loader dalvik.system.PathClassLoader[/system/framework/twframework.jar:/system/framework/sec_feature.jar:/system/framework/sechardware.jar:/system/app/Browser.apk]
08-26 18:14:35.305: E/AndroidRuntime(9427):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-26 18:14:35.305: E/AndroidRuntime(9427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-26 18:14:35.305: E/AndroidRuntime(9427):     ... 30 more

3 个答案:

答案 0 :(得分:0)

快点去看看。

final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
activity.startActivity(intent);

或..

Uri uriUrl = Uri.parse("http://www.google.com/");   
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);

答案 1 :(得分:0)

我觉得AndroidManifest.xml中的活动缺失如下:

<activity
            android:name="dev.socialnet.server.Server"
            android:label="@string/app_name">

        </activity>

答案 2 :(得分:0)

我设法通过从intent中删除包含classname的额外内容来解决问题。 就我而言,它是“clazz = com.example.ExampleActivity”。为了删除额外的内容,我在my活动的startActivity方法中执行了此操作。

@Override
public void startActivity( final Intent intent, final Bundle options )
{
    intent.removeExtra( "clazz" );
    super.startActivity( intent, options );
}

仅供参考:我通过覆盖WebViewClient的shouldOverrideUrlLoading从webview打开链接(mailto和http)时遇到了问题。

希望这有助于某人(花了我2.5小时才找到解决方案)。