按下webview

时间:2013-01-08 16:17:17

标签: android layout webview runtime-error

我一劳永逸地学习了很多时间......我的代码运行得很完美。问题是按钮webview。所以,我在webview里面的按钮上看到了文字。

public class News extends Activity {

    private WebView webView1;
    private Button newsbutton;
    private ImageView imageView1;

        @Override
        public void onCreate(Bundle savedInstanceState){ 
          super.onCreate(savedInstanceState);
          setContentView(R.layout.news);

          webView1 = (WebView)findViewById(R.id.webView1);
          newsbutton = (Button)findViewById(R.id.newsbutton);
          imageView1 = (ImageView)findViewById(R.id.imageView1);

          webView1.setBackgroundColor(0x00000000);
          webView1.loadUrl("file:///android_asset/news.html");




          newsbutton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    finish();

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"
    android:orientation="vertical" >

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="TODO: DESCRIPTION"
        android:src="@drawable/ic_launcher" />

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView1" />

<Button
    android:id="@+id/newsbutton"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:contentDescription="TODO: DESCRIPTION"
    android:text="Chiudi" />

</RelativeLayout>

logcat的

 346): java.lang.StackOverflowError
E/AndroidRuntime(  346):    at java.util.HashMap.doubleCapacity(HashMap.java:561)
E/AndroidRuntime(  346):    at java.util.HashMap.put(HashMap.java:391)
E/AndroidRuntime(  346):    at java.util.HashSet.add(HashSet.java:95)
E/AndroidRuntime(  346):    at java.nio.charset.Charset.<init>(Charset.java:189)
E/AndroidRuntime(  346):    at com.ibm.icu4jni.charset.CharsetICU.<init>(CharsetICU.java:33)
E/AndroidRuntime(  346):    at com.ibm.icu4jni.charset.CharsetProviderICU.getCharset(CharsetProviderICU.java:62)
E/AndroidRuntime(  346):    at com.ibm.icu4jni.charset.CharsetProviderICU.charsetForName(CharsetProviderICU.java:57)
E/AndroidRuntime(  346):    at java.nio.charset.Charset.forNameInternal(Charset.java:500)
E/AndroidRuntime(  346):    at java.nio.charset.Charset.forName(Charset.java:570)
E/AndroidRuntime(  346):    at com.android.internal.util.FastXmlSerializer.setOutput(FastXmlSerializer.java:292)
E/AndroidRuntime(  346):    at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:180)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl.writeFileLocked(ApplicationContext.java:2757)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl.access$800(ApplicationContext.java:2510)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2695)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3656)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime(  346):    at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime(  346):    at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime(  346):    at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime(  346):    a

1 个答案:

答案 0 :(得分:0)

不完全确定你追求的是什么,但我认为这就是你的意思:

<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"
    android:orientation="vertical" >

    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="TODO: DESCRIPTION"
            android:src="@drawable/ic_launcher" />

    <Button
        android:id="@+id/newsbutton"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:contentDescription="TODO: DESCRIPTION"
        android:text="Chiudi" />

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_above="@id/newsbutton"
        android:layout_below="@id/imageView1" />

</RelativeLayout>