william1229 发表于 2015-6-2 16:11:59

CordovaWebView的问题

本帖最后由 william1229 于 2015-6-2 16:14 编辑

使用CordovaWebView,按照官方文档配置
运行到代码(setContentView(R.layout.main);)处时报错
      class is not a View org.apache.cordova.CordovaWebView
      org.apache.cordova.CordovaWebView cannot be cast to android.view.View
CordovaWebView不是一个android的view,不能转换成android的View
请问這是什么原因造成的?怎么才能解决?

在main.xml中如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<org.apache.cordova.CordovaWebView
    android:id="@+id/tutorialView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</LinearLayout>
在MainActivity中如下
package net.cnpchtxl.htxj;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;

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



public class MainActivity extends Activity implements CordovaInterface {
      private CordovaWebView cwv;
      private final ExecutorService threadPool = Executors.newCachedThreadPool();
      
      @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            cwv = (CordovaWebView) findViewById(R.id.tutorialView);
            cwv.loadUrl("file:///android_asset/www/index.html");

    }
      
    @Override
    public void onDestroy() {
            super.onDestroy();
            if (cwv != null) {
                  cwv.handleDestroy();
            }
    }
   
      @Override
      public void startActivityForResult(CordovaPlugin command, Intent intent,
                        int requestCode) {
                // TODO Auto-generated method stub
               
      }
      @Override
      public void setActivityResultCallback(CordovaPlugin plugin) {
                // TODO Auto-generated method stub
               
      }
      @Override
      public Activity getActivity() {
                // TODO Auto-generated method stub
                return this;
      }
      @Override
      public Object onMessage(String id, Object data) {
                // TODO Auto-generated method stub
                return null;
      }
      @Override
      public ExecutorService getThreadPool() {
                // TODO Auto-generated method stub
                return threadPool;
      }
}

你懂的 发表于 2015-6-3 13:00:13

小菜不懂路过一下
页: [1]
查看完整版本: CordovaWebView的问题