Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know the what's causing "Package name is not a valid package name" when adding a new layout?

I've receiving this error in every project I make, new or otherwise.

Error in Android Studio

I've attempted reinstalling Android Studio fresh without any luck and I've also scoured the Internet for the exact error and nothing seems to be coming up.

Does anyone have an idea of what's causing this error when I add a new layout to my project?

like image 920
Nicholas Dingle Avatar asked Nov 29 '15 12:11

Nicholas Dingle


People also ask

Is not valid package name?

It's simply because you are trying to create new Activity / Layout file in a wrong package. To do so, You have to navigate to app >> java >> firstfolder.

What is the valid package name for Android?

@androiddeveloper - All alphanumeric characters, '. ' and '_' is allowed. However, a package name (or a "sub-package" name for that matter, like "reader" in com.

What should my package name be?

Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com.


3 Answers

Instead of adding the new activity by right clicking on the file labeled "layout", right click on the file labeled "res" to add a new activity and it should work fine.

like image 69
Sophia Virdi Avatar answered Oct 14 '22 16:10

Sophia Virdi


As your screenshot shows,current package name is layout,but maybe you don't have a package named layout,so such error existed.

If you want to add a layout file to your project,you should right click layout folder under res folder,and create a layout file.

like image 42
starkshang Avatar answered Oct 14 '22 16:10

starkshang


Hope this helps

Option 1:

  1. Click the Project tab. From there you can see a dropdown. Click the dropdown and go to Packages and then you can see the layout folder. From there you can create another Blank Activity.

Option 2:

  1. From the dropdown again go to Android. Click the java folder, you can see the package name com.example... Write it down on a paper. Then go to layout and create a blank activity. Change the package name to what you had just wrote down on the paper.

Hope it helps.

like image 24
Michael Joshua Ramos Avatar answered Oct 14 '22 18:10

Michael Joshua Ramos