简体   繁体   中英

Android Studio not recognizing Java objects

For reference I am using 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. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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