0

Eclipse在该行中显示main is not a field or cannot be resolved错误。setContentView(R.layout.main);我试图添加一个导入,import android.R;但它所做的只是导致更多错误。这些错误似乎围绕着其中包含“R”的行。有什么建议么?

这是我的xml文件

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

   <TextView
       android:layout_height="wrap_content"
       android:layout_width="fill_parent"
       android:text="This is the demo of WebView Client"
       android:textSize="20sp"
       android:gravity="center_horizontal">       
   </TextView>

    <ProgressBar
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:layout_gravity="center"
       android:id="@+id/progressBar1"/>      

   <WebView
       android:id="@+id/webview01"
       android:layout_height="wrap_content"
       android:layout_width="fill_parent"
       android:layout_weight="1">
   </WebView>



</LinearLayout>

这是活动文件

   package com.example.xxx;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;



public class MainActivity extends Activity {


    WebView web;
    ProgressBar progressBar;

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

        web = (WebView) findViewById(R.id.webview01);
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);

        web.setWebViewClient(new myWebClient());
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("http://www.technotalkative.com");
    }

    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            return true;

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);

            progressBar.setVisibility(View.GONE);
        }
    }


    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
            web.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
4

1 回答 1

1

您不应该import android.R,而是应该import you.package.name.R使用 android,因为您使用R.layout.main,请确保您在 res/layout 下名为main.xml的布局文件。

于 2013-05-01T02:54:59.913 回答