I read here - How to create new packages in an Android project how to make a package, but I need to make a package inside master package com.example.me.
Every time I try to make new package there, it makes package in src folder, not in com.example.me package.
I mean something like this:
<com.example.me
<package1
<Class1
<package2
if you want to create a package inside the com.example.me , you need to write the new package name as com.example.me.Package1 while adding the New Package
Related
I installed intelliJ and created a package of name "com.company" and created some classes and interfaces in that package. Now I created a new package "myCalculator" and created some classes as well. But now I see my new package is not having the main class, so I need to import the package manually. How do i bring my main class to my new package in IntelliJ. Thank You.
You can just drag your files from package to package. Behind the scenes Java packages are just folders, so its is just the same as moving files between folders.
Use refactor option.
Select a class of a package
right click on it and select refactor
choose move option and enter the desired destination package name
My android project is called MyPlaces. I want to create a library (package) with commomTools classes that LIVES outside the MyPlaces directory; however, every time I open MyPlaces project and create a new module, Android Studio creates a directory INSIDE MyPlaces called commontools. I want to create this commonTools directory outside, as it is shown in the screenshot and I prefer it not to be an android project.
I just want to be able to import the classes from the package from different Android Applications.
How can I do that?
Thank you for your help.
Create a new project and and a module which is library.
Then you can use jitpack.io to import it from Gradle.
Good luck
Emre
Why do I get package name in the top of the page whenever I try to create a java class?
I have written some codes in the past using Eclipse but it had no package name like this. I am just wondering why?
You can see the following.
Your class in contained in the package named asd. This is also shown on the left hand side: project "asd" / package "asd" / Class "Ex1.java"
If you want to get rid of the package, you need to move your class to "default package". Right click on the class -> Refactor -> Move -> choose (default package)
However, I would recommend to work with packages and name them properly. Putting classes into "default package" is considered bad practice.
As you can see in package explorer
you placed your class inside asd package. This happened when you created your class via File->New->Class wizard. If you don't specify any package then by default it will use project name.
So when you confirm such configuration such setup Ex1.java will be placed inside asd folder (package), which means that your code will need at its start information about name of package.
If you don't want to have this package asd; line you can for instance
clean that section from wizard when you create package,
or even remove that line from your code and when Eclipse will ask you how to fix this situation
place cursor in line with problem (first line)
select Edit->Quick fix, or press Ctrl+1)
and chose Move Ex1.java to default package.
But you should avoid using default package. For instance when you export classes from your project to Jar file you will not be able to import them in new projects.
For more info about packages visit official tutorial:
What Is a Package?
Lesson: Packages
All Java classes have specified their address in the beginning of the document. They say
package package_name;
If the class is in the default package (directly in 'src' folder), then there is no package written in the beginning of the class...
You can see here, and try on your own:
I've made a new package in the same project, and I can't seem to run the class in the new package. When I click on Run while in the new class, it doesn't run. Any ideas, on how to run this new class? I'm new to Netbeans and Java. Files look like this:
JavaApplication1 (project name)
Source Packages
javaapplication1
Test.java
javaapplication2
NewClass.java
Does the NewClass have main metod? If yes you have 2 options.
You can select main class for procject by rigth clickong on project and selecting Propperties. And then in Run node select main class as shown in image blow.
2.) You can run specific file from ide by rigth clickin on file and select run file as shown in image below.
Looks like your second package is not considered as source for building you need to change project settings so that second package also gets built
To better organize my classes, I made a few sub-packages (that is an extension in the package's hierarchical name structure).
But to my surprise I have been getting an R cannot be resolved to a variable for like every resource I am trying to use from this project's R file.
The Eclipse's quick fixes options do give the option of importing the particular R file for the package (which contains the sub-packages), But the question is that in the package that I created in the Eclipse's New Application Project wizard, I did not need to import the R file at all, and I always thought it contained the resources for this entire project.
But now after creating sub-packages, I need to import it. SO asking out of curiosity, since a sub-package is nothing (in Java) but an extension in the hierarchical name structure of the package itself (reference), then why doesn't the R file automatically get included in the sub-packages?
R is just a class like any other class (except that Eclipse creates it for you and keeps it updated with your resource IDs).
It is contained in a package - like every other class.
If you want to use it from a different package, you must import it or use the fully qualified name - like you would with any other class.