Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:46:42+00:00 2026-05-30T08:46:42+00:00

I am trying to declare a string array which I will be working with

  • 0

I am trying to declare a string array which I will be working with in my code. I have done this two ways, both of which I thought to be viable options, but one causes my app to crash on load without fail.

Working Code:

private String[] list = {"apple", "pear"};

Not Working Code:

Resources res = getResources();
private String[] list = res.getStringArray(R.array.Fruit);

The weird thing is, the latter code was copied directly from the Android String Resource page. I’ve made sure that the array (In this case titled Fruit) exists, and am now kind of lost.

The Log Cat Error I am getting is as follows:

02-25 12:38:18.015: ERROR/AndroidRuntime(605): FATAL EXCEPTION: main
02-25 12:38:18.015: ERROR/AndroidRuntime(605): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ikiar.appname/com.ikiar.appname.Main}: java.lang.NullPointerException
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.os.Looper.loop(Looper.java:123)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at java.lang.reflect.Method.invoke(Method.java:521)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at dalvik.system.NativeStart.main(Native Method)
02-25 12:58:52.284: ERROR/AndroidRuntime(717): Caused by: java.lang.NullPointerException
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at com.ikiar.appname.Main.<init>(Main.java:24)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at java.lang.Class.newInstanceImpl(Native Method)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at java.lang.Class.newInstance(Class.java:1429)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-25 12:58:52.284: ERROR/AndroidRuntime(717):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)

Thank you for your help!

EDIT: More Log Cat information, Line of code @ location of crash added

@ Location of Crash:

Resources res = getResources();

Solution:

Moved the location of Resources res - getResources(); into the onCreate method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:46:44+00:00Added an answer on May 30, 2026 at 8:46 am

    You’ve set the string-array in the string.xml file. If you want to use:

    private String[] list = res.getStringArray(R.array.Fruit);
    

    Try to create an array.xml file in the values folder and there put your Fruit array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to split a string into an array. This is the code
I'm trying to create a function that will take a string which could be
When trying to declare a static array in my program I receive a static
I'm trying to declare a method in main.h like this: void buildGraph(int gNum, Graph**
I am trying to declare the border of a div using hsl() like this:
I am trying to run an event which will search through the different files
I am trying to create nested array's dynamically from a string that has been
I've been trying to come up with a way to declare array constants in
I have an array of objects that I'm trying to add to the Items
So I'm working on my application and I'm simply trying to declare a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.