android - “main cannot be resolved or is not a field”

标签 android android-layout methods

我在下面的代码中有两个错误。

setContentView(R.layout.main); 

错误显示“main 无法解析或不是字段”。 在 Eclipse 中建议的解决方案是在 layout 类型中创建字段 main

webview = (WebView) findViewById(R.id.web_engine); 

错误显示“main 无法解析或不是字段”。 在 Eclipse 中建议的解决方案是创建 id 类型的 web_engine

我尝试了建议的解决方案。在我的 R.java 中,我在 layout 类型中添加了一个 main ,在 类型中添加了一个 web_engine >id.
但是问题并没有解决。你知道我能做什么吗?

这是我的完整代码。

package com.sql.greekapp;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.sql.greekapp.R;

public class GreekNewsActivity extends Activity {
    WebView webview;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.main);    
        getWindow().setFeatureInt(  Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

        webview = (WebView) findViewById(R.id.web_engine); 
        webview.setWebViewClient(new HelloWebViewClient());
        webview.getSettings().setJavaScriptEnabled(true); 
        webview.getSettings().setPluginsEnabled(true);  
        if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.FROYO)
            webview.getSettings().setPluginState(WebSettings.PluginState.ON); 
        webview.getSettings().setAllowFileAccess(true);        
        webview.getSettings().setBuiltInZoomControls(true);         
        webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webview.loadUrl("http://192.168.10.250/remote"); 



       final Activity MyActivity = this;
       webview.setWebChromeClient(new WebChromeClient() {
       public void onProgressChanged(WebView view, int progress)   
       {
        MyActivity.setTitle("Φόρτωση...");
        MyActivity.setProgress(progress * 100); //svisimo


           if(progress == 100)
            MyActivity.setTitle(R.string.app_name);
         }
       });

    }

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {          
                return false;            
        }    
    }

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

最佳答案

这听起来像是一个常见问题。每次您进行更改时,R.java 文件都会自动重新生成。唯一的问题是在您保存文件和/或清理项目之前更改不会生效。与此同时,你正在使用旧东西。哦,如果你有其他错误。 R.java 根本不会重新生成,但您仍然会收到 R.Blah 消息。您可以删除 R.java 文件并观察,几秒钟后它会“重新生成”。所以是的,只需清理并保存您的项目。

关于android - “main cannot be resolved or is not a field”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18884472/

相关文章:

android - Kindle 的 Android 应用程序如何处理字典查找的点击

Android Kotlin - 以编程方式更改按钮的背景

android - 初始化.rc : service killed and restarts

android - 以编程方式设置色调后,EditText 可绘制隐藏

android - 如何更改 ActionBarSherlock 的选项卡文本颜色?

java - 找不到符号类 drawCircle

perl - 获取给定 Perl 类或模块中的所有方法和/或属性

java - Jsoup getElementsByTag

android - 在 Android Switch 组件上定义自定义样式(主题)

c# - 调用方法本身不好?