Beeeeeeer :
I know many questions like this one already exist, but I looked through them and couldn't find an answer.
For some reason the keyword "array" is underlined in red, and I am getting the error: Cannot resolve "array". I have built the project, checked my xml file, but I just cannot figure out what is wrong.
package com.example.listapp;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
ListView myListView;
String[] fruits;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
myListView = (ListView)findViewById(R.id.my_list_view);
fruits = res.getStringArray(R.array.items);
}
}
Also here is my strings.xml file (under res/values/strings.xml):
<resources>
<string name="app_name">List App</string>
<string-array name="items">
<item>peach</item>
<item>apple</item>
<item>banana</item>
</string-array>
<string-array name="prices">
<item>$1.49</item>
<item>$0.99</item>
<item>$0.89</item>
</string-array>
<string-array name="descriptions">
<item>Fresh peaches from Georgia</item>
<item>Fresh apples from Ohio</item>
<item>Fresh bananas from California</item>
</string-array>
</resources>
The line with the error is:
fruits = res.getStringArray(R.array.items);
Ali :
Replace res
to getResources()
Try like this:
final String[] values = getResources().getStringArray(R.array.items);
Clean
and Re-Build
your projct or Invalid Crashes/ Restart
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=291678&siteId=1