1

I have one class in a file named WeatherContract.java which has a static inner class, as follows:

public class WeatherContract {
...
...
    public static final class WeatherEntry implements BaseColumns {
    ...
    ...
    }
}

Now I am trying to call the inner class in another file called TestWeatherContract.java as follows

...
import com.example.android.sunshine.app.data.WeatherContract;
...

public class TestWeatherContract extends AndroidTestCase {
...
    public void testBuildWeatherLocation() {
        Uri locationUri = WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);
...

Now in the following line, the word "WeatherEntry" is marked in red and when I hover on the word I get the following error "Cannot resolve symbol 'WeatherEntry'.

Uri locationUri = WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);

Please note that I am not getting any error in the import statement, so I'm assuming that there are no errors in stating the path of the class.

Also, I have another file called FetchWeatherTask.java. I have the following import statement at the beginning of the file:

import com.example.android.sunshine.app.data.WeatherContract.WeatherEntry;

In this case, in the import statement again the word "WeatherEntry" is marked in red and I get the error "Cannot resolve symbol 'WeatherEntry'".

Please help. I'm on Android Studio 1.5. I have posted this question earlier, but it was put on hold because I provided incomplete details. So I am posting it again with all details. I'm sorry if I have violated the rules of the community, I am new here. Thank you.

2
  • remove final from WeatherEntry and check Commented Jan 19, 2016 at 14:25
  • I tried that, it didn't work Commented Jan 19, 2016 at 14:32

1 Answer 1

1

WeatherEntry is a class and not a member. To access methods of WeatherEntry you still need an instance of it. E.g.

WeatherContract.WeatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);

should be

WeatherEntry weatherEntry = new WeatherContract.WeatherEntry();
weatherEntry.buildWeatherLocation(TEST_WEATHER_LOCATION);
Sign up to request clarification or add additional context in comments.

1 Comment

except if buildWeatherLocation is a static method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.