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 8322167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:17:22+00:00 2026-06-08T23:17:22+00:00

Can someone tell me why this simple code wont work? In the first activity

  • 0

Can someone tell me why this simple code wont work? In the first activity I have the user choose an option which sends an arraylist to the next activity.
It will not do the else statement and force closes. Thanks guys!

String[] quotes;

ArrayList<String> Dark = new ArrayList<String>();
ArrayList<String> Light = new ArrayList<String>();

Heres the code

if (Dark.isEmpty()){

    Light = i.getStringArrayListExtra("light");
    quotes = Light.toArray(new String[Light.size()]);
} else {

    Dark = i.getStringArrayListExtra("dark");
    quotes = Dark.toArray(new String[Dark.size()]); 
};

here is how i send it

 public void dark (View d){
    dark.add("Even 0 is a number, just leave him alone!");
    dark.add("Love is noting but a bad spell, cast onto your soul, never to be released into the wild...");
    dark.add("The end is near please do not make the same mistakes.");
    dark.add( "Jenna i love you, youre my little beandip, dive you!");
    dark.add( "cute hate but dont rate im no skate");
    dark.add("You will never live if you live a lie");
    Intent intent = new Intent(choose.this,Startme.class);
    intent.putStringArrayListExtra("dark",dark);
    startActivity(intent);
 }

public void light (View l) {
    light.add("Good ideas will come if you share your love");
    light.add("enter a world with no doubt, join god");
    light.add("come on, can you live a life");
    light.add( "where love is so is hate lol not");
    light.add( "watch me now!! go with me and join the lord");
    light.add("never be afrade of the darkness");

    Intent intent = new Intent(choose.this,Startme.class);
    intent.putStringArrayListExtra("light",light);
    startActivity(intent);
}

Log

07-30 17:41:33.457: E/AndroidRuntime(15638): FATAL EXCEPTION: main
07-30 17:41:33.457: E/AndroidRuntime(15638): java.lang.RuntimeException: Unable to start activity ComponentInfo{me.me.quote/me.me.quote.Startme}: java.lang.NullPointerException
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.os.Looper.loop(Looper.java:130)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread.main(ActivityThread.java:3806)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at java.lang.reflect.Method.invokeNative(Native Method)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at java.lang.reflect.Method.invoke(Method.java:507)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at dalvik.system.NativeStart.main(Native Method)
07-30 17:41:33.457: E/AndroidRuntime(15638): Caused by: java.lang.NullPointerException
07-30 17:41:33.457: E/AndroidRuntime(15638):    at me.me.quote.Startme.onCreate(Startme.java:164)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-30 17:41:33.457: E/AndroidRuntime(15638):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
07-30 17:41:33.457: E/AndroidRuntime(15638):    ... 11 more

Here is the full code:

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.startquotes);

    Intent i = getIntent(); 

    if (Dark.isEmpty()){

        Light = i.getStringArrayListExtra("light");
        quotes = Light.toArray(new String[Light.size()]);
    } else {

        Dark = i.getStringArrayListExtra("dark");
        quotes = Dark.toArray(new String[Dark.size()]); 
    }

    Button clouds = (Button) findViewById(R.id.Change);
    TranslateAnimation cloud2 = new TranslateAnimation(0, 0, +200, 0);
    clouds.startAnimation(cloud2);
    cloud2.setDuration(1000);

    Button clouds3 = (Button) findViewById(R.id.nxt);
    TranslateAnimation cloud3 = new TranslateAnimation(+200, 0, 0, 0);
    clouds3.startAnimation(cloud3);
    cloud3.setDuration(1000);

    Button clouds4 = (Button) findViewById(R.id.back);
    TranslateAnimation cloud4 = new TranslateAnimation(-200, 0, 0, 0);
    clouds4.startAnimation(cloud4);
    cloud4.setDuration(1000);

    AdView adview = (AdView)findViewById(R.id.adView);
    AdRequest re = new AdRequest();
    re.setTesting(true);
    adview.loadAd(re);

    String ser = SerializeObject.ReadSettings(Startme.this, "myobject.dat");
    if (ser != null && !ser.equalsIgnoreCase("")) {
        Object obj = SerializeObject.stringToObject(ser);
        // Then cast it to your object and 
        if (obj instanceof ArrayList) {
            // Do something
            give = (ArrayList<String>)obj;
        }
    }

    TextView Dark=(TextView)findViewById(R.id.Quote); 

    Typeface face=Typeface.createFromAsset(getAssets(), "fonts/font1.ttf"); 
    Dark.setTypeface(face); 

    num = gen.nextInt(5);
    TextView text = (TextView) findViewById(R.id.Quote);
    text.setText( quotes[num]);

    TextView number = (TextView) findViewById(R.id.Qn);
    number.setText("#"+num);

    TextView Q=(TextView)findViewById(R.id.Qn); 
    Typeface tf=Typeface.createFromAsset(getAssets(), "fonts/titlefont.ttf"); 
    Q.setTypeface(tf); 

    }
}

line 164

    if (Dark.isEmpty()){

        Light = i.getStringArrayListExtra("light");
----------> quotes = Light.toArray(new String[Light.size()]);
    } else {
  • 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-06-08T23:17:23+00:00Added an answer on June 8, 2026 at 11:17 pm

    It will never do your else statement because your Dark arraylist will always be empty. You initialize it like that in your activity and you never read it from your intent. You might want to read both first and decide executing if or else depending on the “null”ity of one. You will see why below.

    The getStringArrayListExtra(key) function will return null by default if the key you give to it does not exist, which means there was never an extra with key “light” added to your intent. This suggests that your light() function is not getting called.

    I would suggest checking your class that includes light() and dark().

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

Sidebar

Related Questions

this must be such a simple problem but can someone tell me why this
Can someone tell me why is this happening? I have created a social networking
Wondering if someone can tell me why this regular expression doesn't work. Expression ->
Please, can someone tell me what does this.init.apply(this, arguments) do in the code below?
if someone could tell me what is wrong with this rather simple code inside
Can someone tell me how to accomplish this mapping using Fluent NHibernate? It's simply
Can someone tell me why this processes all the files and then does it
Can someone tell me why this http://hupcapstudios.com/projects/calendar.html won't load in IE? The error message:
Can someone tell me why this unit test that checks for exceptions fails? Obviously
Can someone tell me where this structure language is from? I am not familiar

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.