Android Studio无法识别Java对象

问题描述 投票:0回答:1

作为参考,我使用的是Android Studio 3.1.4。我的问题是android studio没有识别我的任何java对象,而且所有的对象名称都用红色加下划线。这是我的主要活动的代码:

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);
    }
}
java android android-studio object spinner
1个回答
0
投票

我不太了解您所面临的问题,因为可能有多种原因导致这种情况发生。你可能会发生两件事

    - 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"

之后你应该做一个gradle同步。如果完成所有这些后仍然会得到红线,那么您应该从文件菜单中执行“带有Gradle文件的文件/同步项目”。

在这些步骤之后,所有这些问题都会消失。

如果它仍然出现,那么你应该给我们突出显示时出现的错误。

© www.soinside.com 2019 - 2024. All rights reserved.