2

webview を使用して android にデータをロードしています。正常にロードされていますが、webview に触れると、アプリケーションがクラッシュし、次のエラー メッセージが表示されます。android 4.2 でこの問題に直面しています。 .

私はコードをだますことによって webview をロードしています

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent"></WebView>
</LinearLayout>

ここにコードがあります、

WebView w=(WebView)findViewById(R.id.webView1);
w.loadDataWithBaseURL("http://www.mobilea.pcma.org/mobile/xml/sisap.asp?sid="+str+"&pn=AboutUs", Hold,"text/html", "utf-8",null);

例外の詳細:

01-31 06:27:54.768: W/Trace(1148): Unexpected value from nativeGetEnabledTags: 0
01-31 06:27:54.768: E/InputEventReceiver(1148): Exception dispatching input event.
01-31 06:27:54.778: D/AndroidRuntime(1148): Shutting down VM
01-31 06:27:54.778: W/dalvikvm(1148): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
01-31 06:27:54.948: I/dalvikvm-heap(1148): Clamp target GC heap from 17.720MB to 16.000MB
01-31 06:27:54.948: D/dalvikvm(1148): GC_FOR_ALLOC freed 114K, 3% free 15984K/16384K, paused 49ms, total 51ms
01-31 06:27:55.129: E/AndroidRuntime(1148): FATAL EXCEPTION: main
01-31 06:27:55.129: E/AndroidRuntime(1148): android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ZoomControls
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.inflate(LayoutInflater.java:459)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.ZoomControlExternal$ExtendedZoomControls.<init>(ZoomControlExternal.java:124)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.ZoomControlExternal.createZoomControls(ZoomControlExternal.java:96)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.ZoomControlExternal.getControls(ZoomControlExternal.java:69)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.ZoomControlExternal.show(ZoomControlExternal.java:48)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.ZoomManager.invokeZoomPicker(ZoomManager.java:1208)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.startDrag(WebViewClassic.java:6321)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.handleTouchEventCommon(WebViewClassic.java:6025)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.onHandleUiTouchEvent(WebViewClassic.java:1398)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.onHandleUiEvent(WebViewClassic.java:1331)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.access$7200(WebViewClassic.java:146)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic$PrivateHandler.dispatchUiEvent(WebViewClassic.java:7656)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewInputDispatcher.dispatchUiEvent(WebViewInputDispatcher.java:841)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewInputDispatcher.dispatchUiEvents(WebViewInputDispatcher.java:829)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewInputDispatcher.dispatchUiEvents(WebViewInputDispatcher.java:780)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebViewClassic.onTouchEvent(WebViewClassic.java:5825)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.webkit.WebView.onTouchEvent(WebView.java:1963)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.View.dispatchTouchEvent(View.java:7239)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.View.dispatchPointerEvent(View.java:7419)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4342)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4382)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
01-31 06:27:55.129: E/AndroidRuntime(1148):     at android.view.Choreographer.doCallbacks(Chore
4

2 に答える 2

0

このコードを webview で試してください。Androidのすべてのバージョンで動作します。使用するすべての画像ファイルをコピーして、プロジェクトの「res」フォルダー内のすべての「drawable」フォルダーに貼り付けます。ではごきげんよう..

MainActivity.java:



package com.example.yourappname;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

WebView web;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    web = (WebView) findViewById(R.id.webView1);
    web = new WebView(this);  
    web.getSettings().setJavaScriptEnabled(true);
  
     //change the url below to the url you need
  
    web.loadUrl("http://www.xyxyxyxyxyxy.com");
    web.setWebViewClient(new myWebClient());
    web.setWebChromeClient(new WebChromeClient());
    setContentView(web);
}



public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub

        view.loadUrl(url);
        return true;

    }
    
    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        
    }
}

//flip screen not loading again
@Override
public void onConfigurationChanged(Configuration newConfig){        
  super.onConfigurationChanged(newConfig);
}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            if(web.canGoBack()){
             	web.goBack();
             }
            else
            {
            	backButtonHandler();
            }
            return true;
        }

     }
     return super.onKeyDown(keyCode, event);
 }
public void backButtonHandler() {
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(
				MainActivity.this);
		
	
		// Setting Dialog Title
	   // Setting Dialog Message
      // You can delete the next 2 lines if you wish
		
		alertDialog.setTitle("");
		alertDialog.setIcon(R.drawable.dialog_icon);
		alertDialog.setMessage("Exit Now?");
		
	     // Setting Icon to Dialog
		// Setting Positive "Yes" Button
		
		alertDialog.setPositiveButton("Exit",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						finish();
					}
		});
		
	// Setting Negative "NO" Button
		
		alertDialog.setNegativeButton("No",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						// Write your code here to invoke NO event
						dialog.cancel();
					}
				});
	// Showing Alert Message
		alertDialog.show();
}

}
AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yourappname"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="21" />
    
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permissions.NETWORK_ACCESS" />
    <uses-permission android:name="android.permissions.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo_name_here"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



activity_main.xml:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

于 2014-12-27T10:21:48.573 に答える
0

loadUrl で試してください

WebView w=(WebView)findViewById(R.id.webView1);
w.loadUrl("http://www.mobilea.pcma.org/mobile/xml/sisap.asp?sid="+str+"&pn=AboutUs");
于 2013-01-31T06:43:45.990 に答える