简体   繁体   English

无法解析findViewById和onCreate方法

[英]Cannot resolve findViewById and onCreate methods

I'm new to android and wanted to do a simple program, but while I'm coding the Android Studio doesn't understand findViewById and onCreate and etc that I've mentioned in the code. 我是android新手,想做一个简单的程序,但是在编写代码时,Android Studio无法理解代码中提到的findViewById和onCreate等。 Here is my code and the error is: "Cannnot resolve...." 这是我的代码,错误是:“无法解析...。”

package ir.maharban.measuretechs;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import ir.maharban.measuretechs.R;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button btnCalc = (Button)findViewById(R.id.btnCalc);

    }


}

My Code 我的密码

Try to clean your project maybe. 尝试清理您的项目。 Build > clean project. 生成>清理项目。

  1. Please be patient. 请耐心等待。 Studio takes some time to settle. 工作室需要一些时间才能解决。
  2. Try cleaning the project & Rebuild. 尝试清理项目并重建。
  3. Try updating your repositories. 尝试更新您的存储库。

have you add this Library App compact in your project 您是否在项目中添加了这个Library App compact

just write this code in your build project: 只需在您的构建项目中编写以下代码:

dependencies {
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:appcompat-v7:18.0.+'
}

and Rebuild your android Studio this will run perfect ! 并重建您的android Studio,这将完美运行!

Hope this will help you ! 希望这个能对您有所帮助 ! Cheers ! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM