开发者

Android webview crashing?

开发者 https://www.devze.com 2023-04-01 23:00 出处:网络
I\'m trying to make an app for a website, basically just loads the website. I know how to make it and everything, and I\'ve set up webviews, but I\'m not sure what I\'m doing wrong.

I'm trying to make an app for a website, basically just loads the website. I know how to make it and everything, and I've set up webviews, but I'm not sure what I'm doing wrong.

So basically my main class loads a menu, it has buttons for like home, forums, inbox, etc. That all works fine, but when I hit a button, that calls the webview, and that's when it crashes.

Here's my code for the webview:

public class OpenHome extends Activity{

WebView myWebView;

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    WebView myWebView = (WebView) findViewById(R.id.WebView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("http://www.se7ensins.com");


}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the BACK key and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
        myWebView.goBack();
        return true;
    }
    // If it wasn't the BACK key or there's no web page history, bubble up to the       default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}   

I have all the imports and stuff, but when I run the webview and try to load the page, it just unexpectedly closes the app, also I enabled internet permissions in the android manifest.

Here's the Logcat:

    09-03 06:08:03.287: DEBUG/AndroidRuntime(563): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
09-03 06:08:03.287: DEBUG/AndroidRuntime(563): CheckJNI is ON
09-03 06:08:04.177: DEBUG/AndroidRuntime(563): Calling main entry com.android.commands.pm.Pm
09-03 06:08:04.217: DEBUG/AndroidRuntime(563): Shutting down VM
09-03 06:08:04.237: DEBUG/dalvikvm(563): GC_CONCURRENT freed 100K, 84% free 339K/2048K, paused 0ms+0ms
09-03 06:08:04.237: INFO/AndroidRuntime(563): NOTE: attach of thread 'Binder Thread #3' failed
09-03 06:08:04.247: DEBUG/jdwp(563): Got wake-up signal, bailing out of select
09-03 06:08:04.247: DEBUG/dalvikvm(563): Debugger has detached; object registry had 1 entries
09-03 06:08:04.887: DEBUG/AndroidRuntime(573): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
09-03 06:08:04.887: DEBUG/AndroidRuntime(573): CheckJNI is ON
09-03 06:08:05.886: DEBUG/AndroidRuntime(573): Calling main entry com.android.commands.am.Am
09-03 06:08:05.936: INFO/ActivityManager(79): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.clepto.sinnergy/.SinnergyActivity } from pid 573
09-03 06:08:05.969: WARN/WindowManager(79): Failure taking screenshot for (230x143) to layer 21005
09-03 06:08:05.996: INFO/ActivityManager(79): Start proc com.clepto.sinnergy for activity com.clepto.sinnergy/.SinnergyActivity: pid=581 uid=10036 gids={3003}
09-03 06:08:06.057: DEBUG/AndroidRuntime(573): Shutting down VM
09-03 06:08:06.086: INFO/AndroidRuntime(573): NOTE: attach of thread 'Binder Thread #3' failed
09-03 06:08:06.186: DEBUG/dalvikvm(573): GC_CONCURRENT freed 101K, 83% free 364K/2048K, paused 1ms+1ms
09-03 06:08:06.186: DEBUG/jdwp(573): Got wake-up signal, bailing out of select
09-03 06:08:06.186: DEBUG/dalvikvm(573): Debugger has detached; object registry had 1 entries
09-03 06:08:08.057: DEBUG/dalvikvm(581): GC_FOR_ALLOC freed 32K, 3% free 6345K/6531K, paused 71ms
09-03 06:08:08.078: INFO/dalvikvm-heap(581): Grow heap (frag case) to 6.828MB for 614416-byte allocation
09-03 06:08:08.186: DEBUG/dalvikvm(581): GC_FOR_ALLOC freed <1K, 4% free 6945K/7175K, paused 79ms
09-03 06:08:08.356: DEBUG/dalvikvm(581): GC_CONCURRENT freed <1K, 4% free 6945K/7175K, paused 20ms+3ms
09-03 06:08:08.616: DEBUG/dalvikvm(147): GC_EXPLICIT freed 7K, 18% free 14098K/17159K, paused 5ms+376ms
09-03 06:08:08.656: DEBUG/dalvikvm(581): GC_CONCURRENT freed 779K, 12% free 6715K/7559K, paused 5ms+3ms
09-03 06:08:08.676: VERBOSE/TLINE(581): new: android.text.TextLine@4063b850
09-03 06:08:09.216: VERBOSE/TLINE(581): new: android.text.TextLine@4072ad08
09-03 06:08:09.279: INFO/ActivityManager(79): Displayed com.clepto.sinnergy/.SinnergyActivity: +3s288ms
09-03 06:08:10.216: DEBUG/dalvikvm(147): GC_EXPLICIT freed <1K, 18% free 14099K/17159K, paused 229ms+4ms
09-03 06:08:13.236: INFO/ActivityManager(79): Starting: Intent { act=com.clepto.sinnergy.OPENHOME } from pid 581
09-03 06:08:13.247: DEBUG/AndroidRuntime(581): Shutting down VM
09-03 06:08:13.247: WARN/dalvikvm(581): threadid=1: thread exiting with uncaught exception (group=0x40014760)
09-03 06:08:13.256: ERROR/AndroidRuntime(581): FATAL EXCEPTION: main
09-03 06:08:13.256: ERROR/AndroidRuntime(581): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.clepto.sinnergy.OPENHOME }
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.app.Activity.startActivityForResult(Activity.java:3095)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.app.Activity.startActivity(Activity.java:3201)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at com.clepto.sinnergy.SinnergyActivity$1.onClick(SinnergyActivity.java:34)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.view.View.performClick(View.java:3110)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.view.View$PerformClick.run(View.java:11928)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.os.Handler.handleCallback(Handler.java:587)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.os.Looper.loop(Looper.java:132)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at android.app.ActivityThread.main(ActivityThread.java:4025)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at java.lang.reflect.Method.invoke(Method.java:491)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
09-03 06:08:13.256: ERROR/AndroidRuntime(581):     at dalvik.system.NativeStart.main(Native Method)
09-03 06:08:13.276: WARN/ActivityManager(79):   Force finishing activity com.clepto.sinnergy/.SinnergyActivity
09-03 06:08:13.276: WARN/WindowManager(79): Failure 开发者_运维知识库taking screenshot for (230x143) to layer 21010
09-03 06:08:13.800: WARN/ActivityManager(79): Activity pause timeout for ActivityRecord{41470780 com.clepto.sinnergy/.SinnergyActivity}
09-03 06:08:16.542: INFO/Process(581): Sending signal. PID: 581 SIG: 9
09-03 06:08:16.566: INFO/ActivityManager(79): Process com.clepto.sinnergy (pid 581) has died.
09-03 06:08:16.566: INFO/WindowManager(79): WIN DEATH: Window{4144bae8 com.clepto.sinnergy/com.clepto.sinnergy.SinnergyActivity paused=false}
09-03 06:08:16.696: WARN/InputManagerService(79): Got RemoteException sending setActive(false) notification to pid 581 uid 10036
09-03 06:08:16.930: INFO/dalvikvm(79): Jit: resizing JitTable from 2048 to 4096
09-03 06:08:22.138: DEBUG/SntpClient(79): request time failed: java.net.SocketException: Address family not supported by protocol
09-03 06:08:24.788: WARN/ActivityManager(79): Activity destroy timeout for ActivityRecord{41470780 com.clepto.sinnergy/.SinnergyActivity}


I think your code is almost perfect..

just need to change one line

write this line

myWebView = (WebView) findViewById(R.id.WebView);

instead of

 WebView myWebView = (WebView) findViewById(R.id.WebView);

just remove WebView object bcz you already define in global..

and may be some problem in you webview.xml file ?

check it first.

here is samle code for webview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <android.webkit.WebView android:id="@+id/WebView"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
    </android.webkit.WebView>
</LinearLayout>

Update One thing did you add .OpenHome activity in your menifest.xml file

How to check LogCat

go Window >> Show view >> other >> Android >> LogCat

How to add activity in menifest.xml

open AndroidMenifest.xml from you project directory and add this line

<activity android:name=".OpenHome"></activity>

how to start new activity

Intent intent = new Intent(your_main_class.this,OpenHome.class); 
startActivity(intent);

where your_main_class is your main class name .


This is not because of webview.

FATAL EXCEPTION: main 09-03 06:08:13.256: ERROR/AndroidRuntime(581): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.clepto.sinnergy.OPENHOME }

This error is because of the activity is not defined in manifest. Verify the package and class name of your activity in manifest carefully.

0

精彩评论

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