简体   繁体   English

Android Studio无法识别Java对象

[英]Android Studio not recognizing Java objects

For reference I am using Android Studio 3.1.4. 供参考,我使用的是Android Studio 3.1.4。 My problem is that android studio isn't recognizing any of my java objects aka all of the objects names are underlined in red. 我的问题是android studio无法识别我的任何Java对象,也就是所有对象名称都用红色下划线标出。 Here is the code for my main activity: 这是我主要活动的代码:

package com.example.t00587599.unitconverter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AdapterView;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Spinner spinner = findViewById(R.id.spinner);
        ArrayAdapter<CharSequence>  adapter = ArrayAdapter.createFromResource(context: this, R.array.temptypes, android.R.layout.simple_spinner_item);



        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    }
}

I donot know much about the issues that you are facing as there can be multiple reasons why that is happening. 我对您所面临的问题了解不多,原因可能有多种。 There are two things that you could be happening 您可能会发生两件事

    - if your package is compiled then you should check if the files are in the project. Or the project where the package is included is added in the build.gradle. I do this by adding

             compile ":unitconverter"

    - if you are including this as a compiled dependency then you can add the following line in your build.grade for the project
             compile "com.example.t00587599.unitconverter"

After that you should do a gradle sync. 之后,您应该执行gradle同步。 If after doing all this you still get the red lines then you should do a "File/Sync Project with Gradle Files" from the file menu. 如果完成所有这些操作后仍然出现红线,则​​应从文件菜单中执行“带有Gradle文件的文件/同步项目”。

All of these class of problems disappear after these steps for me. 这些步骤对我来说所有这些问题都会消失。

If it still appears then you should give us the error that come when you highlight it. 如果它仍然出现,那么当您突出显示它时,您应该给我们带来的错误。

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

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