question on src folders in eclipse
So, I've been doing android application tutorials and everytime I create a package开发者_StackOverflow中文版, for example the helloAndroid tutorial is com.example.android. When it saves this to src it creates a folder for com, another for example and one last one for android. So it gives me the error "class com.example.android does not exist" because its broken into different folders.
I remember being confused about this when I first started learning Java too!
Packages and folders are a weird concept in Java.
A package is a declaration of where your java file lives.
so a package declaration of
package com.folder1.folder2.folder3;
means your class will live in the folder
com/folder1/folder2/folder3;
There are some standards applied. For example, the first part 'com' denotes what kind of code this is. Company? Organization? Java eXtension? The second part denotes the name of your company or organization.
For example:
package org.stackoverflow.utils;
Each package will have a folder in the src tree. If you are getting class not found errors in eclipse you can press ctrl + shift + O to fix them.
精彩评论