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

  • Home
  • SEARCH
  • 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 3454576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:30:36+00:00 2026-05-18T09:30:36+00:00

I am writing an Android app where I need to pass a string array

  • 0

I am writing an Android app where I need to pass a string array between two classes. The string initializes fine and I can output the contents of the string fine in the one class but as I try to pass it to another class I get a Null Pointer Exception error. The following is the stripped down version of my code:

accelerometer.java:

    public class accelerometer extends Service {

 public String movement[];

 public void onCreate() {

  movement = new String[1000000];

 }

 public void updatearray() {
  movement[arraypos]=getCurrentTimeString();
  //Toast.makeText(this, movement[arraypos] , Toast.LENGTH_SHORT).show(); //this correctly displays each position in the array every time it updates so I know the array is working correctly in this file
  arraypos+=1;
 }

 public String[] getmovement(){
  return movement;
 }
    }

wakeupalarm.java:

    public class wakeupalarm extends Activity {

 private TextView herestext_;

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

  herestext_ = (TextView) findViewById(R.id.TextView01);

  accelerometer accelerometercall = new accelerometer();

  String movearray[] = accelerometercall.getmovement();

  herestext_.setText(movearray[2]);
  }

    }

I have a feeling I’m missing something very simple but any help would be greatly appreciated!

Thanks,

Scott

  • 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-18T09:30:36+00:00Added an answer on May 18, 2026 at 9:30 am

    You’re creating a new accelerometer class, which is completely uninitialized since there is no constructor, then you access its member. Of course it’ll be null.

    Not sure how your two classes are related, but if the activity is called by the service, then you need to pass the string through the intent (through an extra, for example).

    Side note: Class names should always start with a capital letter. Method/variable names should have camel case, i.e. “updateArray”. Also, you can format your code here by selecting it and pressing CTRL+K.

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

Sidebar

Related Questions

I am writing an android app. I want to pass some data across the
I'm writing an android app where I need to use AES. Is it better
I'm writing an Android App and I'm looking for the fastest (In terms of
I'm writing my first location based android app, but got confused about some of
I am writing a simple Android app and have a database that will send
I'm writing an android app and in it I want to have a sort
I am writing an Android App where I am playing video using VideoView,but the
I'm writing an Android app for work that shows the status of our phone
My Android app is reading and writing to a local SQLite DB from a
I am writing my first simple Android App: It loads temperature samples from a

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.