1

ボタンを Web ビューの上に配置しようとしていますが、最も簡単な方法は xml を使用することです。私の MainActivity onCreate は次のようになります。

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button buttonClick = (Button)findViewById(R.id.playButton);

        mWebview  = (WebView)findViewById(R.id.webview);
        mWebview.getSettings().setJavaScriptEnabled(true); // enables javascript


        System.out.println("Loading Webpage...");
        new tts().execute("");
        mWebview.loadUrl("http://www.aljazeera.com/news/americas/2013/07/20137113200544375.html");
        mWebview.addView(buttonClick);
        setContentView(mWebview);

    }

私の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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

<WebView 
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
    <Button
        android:id="@+id/playButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Pause" />

</RelativeLayout>

何らかの理由で、null ポインター例外で致命的なエラーが発生しています。なぜこれが起こっているのか、誰にも洞察がありますか?

4

2 に答える 2