sandeep addala
sandeep addala

Reputation: 117

Not able to create new Activity in android studio(NullPointerException)

When I try to create a new activity it says NullPointerException

enter image description here

It says IDE fatal when I tried look into the error from the event log

enter image description here

Upvotes: 4

Views: 6283

Answers (5)

imok1948
imok1948

Reputation: 91

Because you have another layout/activity/menu/or other things. I faced the same issue, it inserts the activity into Manifest but never creates a new file. Try these things Try to use another name activity/fragment/... Delete other unnecessary things/files e.g. from drawable, files created previously in other directories as well.

Upvotes: 0

Saurabh Padwekar
Saurabh Padwekar

Reputation: 4074

Follow the below steps:

Open the folder bin under the directory where you installed your Android Studio.

Open the file "idea.properties" and open it with Notepad++/UltraEdit/other_edit_tools.

Add "disable.android.first.run=true" as the final line and save the file.

Upvotes: 0

Himanshu Nain
Himanshu Nain

Reputation: 56

You may not have created entry for intent-filter in manifest.If you are creating both java and layout file separately without directly creating a activity.

  1. Create a java file say Main.java

use following code :

public class Main extends AppCompatActivity{

@Override
protected void onCreate(Bundle savedState)
{
  super.onCreate(savedState);
  setContentView(R.layout.your_layout);
}

and in manifest add after application tag

<activity
      android:name=".Main">
      <intent-filter>
           <action android:name="android.intent.action.MAIN"/>
           <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
</activity>

Upvotes: 1

sandeep addala
sandeep addala

Reputation: 117

Oops!! I was doing it wrong There is no Issue if I create the new Activity this way.

Creating new activity from the project window

Upvotes: 1

Sagar Aghara
Sagar Aghara

Reputation: 640

Try this following things...

  • Try to Build Your Project.
  • Try to Clean your Project.
  • If not work then Restart Project/Android Studio.
  • If still not work Then try to Add Activity with Right click and Add New Java Class.
  • And check SDK is proper

and let me know what happens.

Hope this will helps...(:

Upvotes: -1

Related Questions