Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding java folders to android studio project

Tags:

Started working on my first project using Android Studio instead of Eclipse ADT. I would like to add sub folders to contain java.classes in order to structure my app but are unable to obtain references to them in my activity

structure is (with app name replaced)

src/main/[MyCompany]/[myAppName]/model/user.java 

and

src/main/[MyCompany]/[myAppName]/helperClasses/SQLiteHelper.java 

however I am unable to reference them either directly in code or by import, and are forced to put them in the appName folder with the activity to reference them.

Is this simply a limitation in Android or is there a way to organize your project with folders better. I used the new->folder-java folder option to create folders

like image 268
Essah Avatar asked Dec 18 '14 05:12

Essah


People also ask

What is Java folder in Android Studio?

The Java folder contains all the java and Kotlin source code (. java) files that we create during the app development, including other Test files. If we create any new project using Kotlin, by default the class file MainActivity. kt file will create automatically under the package name “com.

Which folder contains the Android project Java files?

The src folder holds two most important folders on any Android project, namely, androidTest and main. The androidTest package is created to hold Test cases for testing the application code and running. This folder contains . java (JAVA) files.

How do I create a folder in Android project?

Step 1: To create an asset folder in Android studio open your project in Android mode first as shown in the below image. Step 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. Step 3: Android Studio will open a dialog box. Keep all the settings default.


2 Answers

IntelliJIdea mixes packages and directories.

So, right click on the java folder, click new - 'Package', then add your directory.

like image 89
David McEleney Avatar answered Oct 01 '22 21:10

David McEleney


In my case I wanted a mock package with java folder:

  1. First step you have to put project mode:

enter image description here

  1. Click right button, new, Directory, in my case "mock".
  2. Click right button, new, Folder, Java Folder:

enter image description here

  1. Click in checkbock "change folder location" and put your path, in my case "src/mock/java":

enter image description here

  1. The solution is this:

enter image description here

like image 40
Cabezas Avatar answered Oct 01 '22 21:10

Cabezas