【问题标题】:Android Studio not recognizing Java objectsAndroid Studio 无法识别 Java 对象
【发布时间】:2018-09-15 10:50:21
【问题描述】:

作为参考,我使用的是 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】:

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

        - 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 文件的文件/同步项目”。

    对我来说,在这些步骤之后,所有这些问题都消失了。

    如果它仍然出现,那么您应该在突出显示它时告诉我们出现的错误。

    【讨论】:

    • 您指的是哪些文件?您的意思是我应该将该代码复制并粘贴到我的 build.gradle 文本文件中吗?如果有,在哪里?
    • 如果你有你的包的源代码,那么你应该将 unitconverter 作为一个模块添加到你的项目中。我的意思是构成该包的所有文件(src/res/manifest)。然后你可以添加 - 编译 ":unitconverter" 并且你的项目将构建
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 2013-05-10
    • 2021-05-06
    相关资源
    最近更新 更多