0

In my app, there is a registration button which is supposed to open an activity named "registrationActivity" I tried this:

In XML file:

<Button
    android:id="@+id/btnRegister"
    android:onClick="startRegister"
/>

In Java file:

public void startRegister(View view)
    {
        Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
        startActivity(intent);
    }

but every time I click the register button, the app keeps stopping.

Edit 1: error from logcat:

Runtime: FATAL EXCEPTION: main Process: com.test.stork, PID: 5152

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test.stork/com.test.stork.RegistrationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference

Edit 2: I found the problem in the registrationActivity itself and now it works. Thanks so much everyone.

  • 1
    Post the stack trace from logcat. It will tell you why you're crashing. Which is more likely to be in the new activity than the old one. – Gabe Sechan Aug 30 '18 at 13:53
  • 1
    Is the `RegistrationActivity` mentioned in the Manifest ? – Bruno Aug 30 '18 at 13:55
  • Please show the full stacktrace – OneCricketeer Aug 30 '18 at 14:05
  • yes, it's declared in manifest but still not working – YomnaEldawy Aug 30 '18 at 14:06
  • Edit your question to include the full Activity, your layout and manifest. See [mcve] for more information – OneCricketeer Aug 30 '18 at 14:06
  • Possible duplicate of [Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference](https://stackoverflow.com/questions/36666091/attempt-to-invoke-virtual-method-android-view-windowcallback-android-view-wind) – dilix Aug 30 '18 at 14:08

2 Answers2

0

Like Bruno mentioned in the comments, you need to declare the RegistrationActivity in your manifest file like :

<activity
    android:name="yourPackage.RegistrationActivity"/>

under the application object.

Bubu
  • 1,533
  • 14
  • 14
0

The issue is in your Registration Activity onCreate or onResume method. Post your Registration xml. Basically it is failing to do something with a null object in your startup. Set a break point in your onCreate of your RegisterActivity and see which item is null and you will be good.

Sam
  • 5,342
  • 1
  • 23
  • 39