2013-07-31 2 views
1

도와주세요. 내 HTML 페이지를 안드로이드에 표시하려했습니다. 그러나 그것은 오류를 보여줍니다.android : WebView, 자산 폴더의 HTML 콘텐츠 표시

XML에 내 코드,

자바로
<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scrollbars="vertical" /> 

; 응용 프로그램을 실행하는 동안 다음과 같이

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    WebView wv; 
    wv = (WebView) findViewById(R.id.webview); 
    wv.loadUrl("file:///android_asset/chapter1.html"); 
} 

}

하지만, ...는 많은 오류를 표시;

07-31 11:04:05.056: D/AndroidRuntime(1008): Shutting down VM 
07-31 11:04:05.096: W/dalvikvm(1008): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 
07-31 11:04:05.136: E/AndroidRuntime(1008): FATAL EXCEPTION: main 
07-31 11:04:05.136: E/AndroidRuntime(1008): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thaufeeq.tamilquran/com.thaufeeq.tamilquran.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.os.Looper.loop(Looper.java:137) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread.main(ActivityThread.java:5041) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at java.lang.reflect.Method.invoke(Method.java:511) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at dalvik.system.NativeStart.main(Native Method) 
07-31 11:04:05.136: E/AndroidRuntime(1008): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.createView(LayoutInflater.java:613) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.Activity.setContentView(Activity.java:1881) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at com.thaufeeq.tamilquran.MainActivity.onCreate(MainActivity.java:13) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.Activity.performCreate(Activity.java:5104) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  ... 11 more 
07-31 11:04:05.136: E/AndroidRuntime(1008): Caused by: java.lang.reflect.InvocationTargetException 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at java.lang.reflect.Constructor.constructNative(Native Method) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  ... 23 more 
07-31 11:04:05.136: E/AndroidRuntime(1008): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060001 a=-1 r=0x7f060001} 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.content.res.Resources.loadDrawable(Resources.java:1927) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.View.<init>(View.java:3330) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.View.<init>(View.java:3259) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.view.ViewGroup.<init>(ViewGroup.java:425) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:210) 
07-31 11:04:05.136: E/AndroidRuntime(1008):  ... 26 more 
+1

문제가 XML 파일에있는 것으로 보인다. RelativeLAyout에 찾을 수없는 드로어 블을 설정하려고합니까? 당신은 XML의 RelativeLAyout 부분을 게시 할 수 있습니까? RelativeLayout 및 리소스를 찾을 수 없습니다 오류가 발생합니다. –

답변

1

사용자의 권리. 이 코드는 내가 체크했을 때 작동한다. 더 나은, 당신은이 코드를 아래 코드로 대체하여이 코드로 디버그를 다시합니다. (NO MORE 수정본)

자바 FILE :

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.webkit.WebView; 

public class Webview extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_webview); 
     WebView wv; 
     wv = (WebView) findViewById(R.id.webview); 
     wv.loadUrl("file:///android_asset/chapter1.html"); 
    } 
} 

당신의 XML 코드 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Webview" > 

<WebView android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/webview"> 
</WebView> 

</RelativeLayout> 
0

자산에서 sdcard로 파일을 복사 할 때도 동일한 문제가 발생했습니다. 내 문제가 해결되었습니다. 가능한 경우 AssetManager 클래스를 한 번 살펴보십시오.

private void copyAssets() { 
    AssetManager assetManager = getAssets(); 
    String[] files = null; 
    try { 
     files = assetManager.list(""); 
    } catch (IOException e) { 
     Log.e("tag", "Failed to get asset file list.", e); 
    } 
    for (String filename : files) { 
     InputStream in = null; 
     OutputStream out = null; 
     try { 
      in = assetManager.open(filename); 
      File f = new File(Controller.getController() 
        .getApplicationBasePath() + "/Document_Directory"); 
      if (f.exists()) { 
       out = new FileOutputStream(Controller.getController() 
         .getApplicationBasePath() 
         + "/Document_Directory/" 
         + filename); 

       copyFile(in, out); 
       in.close(); 
       in = null; 
       out.flush(); 
       out.close(); 
       out = null; 
      } else { 
       f.mkdir(); 
       copyAssets(); 
      } 
     } catch (IOException e) { 
      Log.e("tag", "Failed to copy asset file: " + filename, e); 
     } 
    } 
} 
관련 문제