[英]Android Studio not recognizing Java objects
供參考,我使用的是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);
}
}
我對您所面臨的問題了解不多,原因可能有多種。 您可能會發生兩件事
- 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文件的文件/同步項目”。
這些步驟對我來說所有這些問題都會消失。
如果它仍然出現,那么當您突出顯示它時,您應該給我們帶來的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.