Arturo Lozano :
Cannot resolve symbol 'array'
I am trying to get an array of strings from my res/values/strings.xml and feed it into an array, but the mentioned error above occurs.
Here is my java class
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.res.Resources;
import android.os.Bundle;
public class ListViewActivity extends AppCompatActivity {
Resources res;
String[] items;
String[] prices;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
res = getResources();
items = res.getStringArray(R.array.items);
}
}
And here is the XML
<resources>
<string name="app_name">Poker Ledger</string>
<string name="title_activity_login">Sign in</string>
<string name="prompt_email">Email</string>
<string name="prompt_password">Password</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="welcome">"Welcome !"</string>
<string name="invalid_username">Not a valid username</string>
<string name="invalid_password">Password must be >5 characters</string>
<string name="login_failed">"Login failed"</string>
<string-array name="items">
<item>Apple</item>
<item>Banana</item>
<item>Oranges</item>
</string-array>
<string-array name="prices">
<item>$1.25</item>
<item>$1.50</item>
<item>$1.75</item>
</string-array>
Logcat keeps reapting this:
2020-03-10 22:40:23.747 2107-4262/system_process D/WificondControl: Scan result ready event
2020-03-10 22:40:24.688 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: a: input svInfo.flags is 8
2020-03-10 22:40:24.688 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2020-03-10 22:40:25.687 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: a: input svInfo.flags is 8
2020-03-10 22:40:25.687 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2020-03-10 22:40:26.687 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: a: input svInfo.flags is 8
2020-03-10 22:40:26.687 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2020-03-10 22:40:27.687 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: a: input svInfo.flags is 8
2020-03-10 22:40:27.688 1749-2755/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2020-03-10 22:40:27.697 2107-3169/system_process W/AppOps: Noting op not finished: uid 10102 pkg com.google.android.gms code 41 time=1583901621696 duration=0
InsaneCat :
Write like below snippet and please refer below answers:
final String[] values = getResources().getStringArray(R.array.string_array);
String.XML
<resources>
<string-array name="string_array">
<item>one</item>
<item>two</item>
<item>three</item>
</string-array>
</resources>
Click Me & Click Me & Click Me
Hope this may helps you.