带 WebView 的 ViewFlipper 包括

发布于 2024-10-15 11:17:06 字数 1978 浏览 6 评论 0原文

我正在创建一个可以翻转 WebView 的 ViewFlipper:如果我将 WebView 放在 main.xml 中,则运行该应用程序不会出现任何问题。由于我将使用多个 Web 视图,因此我决定将它们分解为单独的 XML 文件。当我在 main.xml 的 ViewFlipper 中使用 include android:id="@+id/myWebView001" layout="@layout/pg001" 执行此操作时,应用程序启动时我会强制关闭。

请仔细阅读以下代码,如果您有任何建议使其正常工作,我们将不胜感激。再次感谢!

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");
  }
}

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");
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-10-22 11:17:06

错误显然很简单。您的主要活动类别为空。我相信他添加了 Pg001.class ,但没有将其与主要活动类链接。如果您确实将其添加到清单文件中,请重试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文