ViewFlipper w/ WebView includes

925 views Asked by At

I am creating a ViewFlipper that flips thru WebViews: I have no problems running the app if I place the WebViews within the main.xml. Since I will be using a multiple count of Web views, I decided to break them up into separate XML files. When I do this using the include android:id="@+id/myWebView001" layout="@layout/pg001" within the ViewFlipper of the main.xml, I get an force close when the app starts.

Please look thru the following code and if you have any suggestions for this to work correctly, it will greatly appreciate it. Thnx again!!

main.xml:

<?xml version="1.0" encoding="utf-8"?>

    <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ViewFlipper" 
        android:layout_width="fill_parent" android:layout_height="fill_parent" >

        <include android:id="@+id/myWebView001"  layout="@layout/pg001" />

    </ViewFlipper>

main.java:

package com.aero.ac4313;

import android.app.Activity;
import android.os.Bundle;

 public class main extends Activity {
 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //set your content view, this will be your layout
    setContentView(R.layout.main);
   }
 }

pg001.xml:

<?xml version="1.0" encoding="utf-8"?>

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

Pg001.java:

package com.aero.ac4313;

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

public class Pg001 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //set your content view, this will be your layout
    setContentView(R.layout.pg001);
    WebView mWebView = null;
    mWebView = (WebView) findViewById(R.id.myWebView001);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("file:///android_asset/pg001.html");
  }
}
1

There are 1 answers

0
wesdfgfgd On

The error is obviously simple. Your main activity class is null. I believe that he added Pg001.class without linking it with the main activity class. If you did add it on the manifest file then try again.