0

I work with interfaces, thus before starting certain activity I create it, assign pointer to the public property of the activity to start (I want to run some function from activity to start and the implementation of course in starting activity) The code

ActivityToStart act = new ActivityToStart ();   
act.delegate = (MyInterface) StartingActivity.this;
Intent i = new Intent(StartingActivity.this,ActivityToStart.class);
act.startActivity(i);

StartingActivity implements MyInterface.

I get an error, unfortunately not informative (null pointer exception)

Why?

Alexander
  • 35
  • 1
  • 8
  • 1
    You get more than a null pointer exception... You get a reference to a line of code and a stack trace... those are there to seriously help. –  Jun 14 '14 at 21:39
  • http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – ben75 Jun 14 '14 at 21:44

1 Answers1

1

Activity classes cannot be directly instantiated.

You must do so via startActivity(), with Intents. To send information, you can add "extras" to the Intent, then read them in the second activity's onCreate() method.

See Starting Another Activity in the documentation.

matiash
  • 54,791
  • 16
  • 125
  • 154