Quantcast
Channel: Null pointer exception while loading from strings.xml in Android - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Anton Tarasov for Null pointer exception while loading from strings.xml in Android

$
0
0

Why don't you create a string-array instead of multiple strings?

<resources>
    <string-array name="questions">
        <item>What year did John say the Beatles were more popular than Jesus?</item>
        <item>What did the Beatles receive for performing three times on The Ed Sullivan Show?</item>
        <!-- ... -->
    </string-array>
</resources>

And then just get it like that:

String[] questions = getResources().getStringArray(R.array.questions);

Also, of course, move your code from initializer to onCreate() or where you can get your context.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>