Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

by Dianne Hackborn » Wed, 21 Apr 2010 05:54:02 GMT


Sponsored Links
 The Java compiler requires that each top-level class be in its own source
file.




>



Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

by ~ TreKing » Wed, 21 Apr 2010 05:54:23 GMT


 



Yes. Which you could have found out on your own in about 5 minutes.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

by patbenatar » Wed, 21 Apr 2010 16:49:36 GMT


 "but in all of the examples I've seen for android all of the methods
and classes are all in one big java file"

Uhhmmmm........ On what sites did you find these examples?









>



Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

by Bob Kerns » Thu, 22 Apr 2010 04:27:09 GMT


 This may or may not be more information than the OP needed. But there
may be confusion there worth clarifying).

Actually, Dianne, that's only true of top-level classes with the
'public' modifier. You can have top-level classes that are package-
private in the same file -- but no more than one 'public'', and the
file must be named with the same name as the class, plus the ".java"
suffix.

However -- that is ALMOST never done!

Binxalot -- I'm afraid you're mistaken -- I'm reasonably certain that
you have NOT seen all the methods and classes in one big java file.

Either you've misunderstood what you were seeing, because it was all
on one web page, or something else. Let's not worry about any
confusion from web page formatting...

If you were actually looking at .java files, then you were probably
thrown off by one of these points:

*) A java class definition cannot be split between files. All methods
and fields will appear within the same file, which will contain the
*complete* definition of that class.

*) A java class definition can contain INNER class definitions. These
are not independent definitions. If they do not include the 'static'
keyword before the 'class' keyword, they can only be instantiated in
the context of an instance of the outer class. If they DO include the
'static' keyword before the 'class' keyword, then you can view them as
being somewhat akin to namespaces in intent. That is, the class name
is available within the scope of that class; to be used elsewhere it
needs to either be explicitly qualified with outer class name, e.g.
(Outer.Inner, or com.example.java.Outer.Inner), or imported with the
'import static' statement.

If you don't wish to do this, then you can instead use packages and
make these inner classes top-level. Eclipse provides convenient
commands to do this.

Note that inner classes that have the 'public' modifier can be
referenced outside the package, and those that have the 'protected'
modifier can be referenced by subclasses of the outer class. Those
with 'private' can only be accessed within the class, and those with
no modifier can only be accessed by other classes within the same
package. This is a bit more flexible than top-level classes, which can
only be 'public' or default (i.e. private to the package).

I hope this helps you read the code a bit easier. It's best to think
of one .java file as being one complete unit; there may be inner and
private classes, but it provides only one top-level class to other
packages, and it provides the complete definition of that class.

The compiler will output each class to its own .class file, including
inner classes. They'll be in the same directory as other classes in
the same package, but with names constructed to avoid conflicts.
Anonymous (nameless) inner classes will get generated names. So all of
these .class files have to be packaged up in an Java application.

On Apr 20, 2:53pm, Dianne Hackborn <hack...@android.com> wrote:

> >



Beginner Question: Is it possible to put each class into it's own java file in Eclispe?

by Dianne Hackborn » Thu, 22 Apr 2010 04:31:27 GMT


 h good point.  In fact I have had non-public classes combined in a public
class's file. And usually quickly regretted it. :)

On Wed, Apr 21, 2010 at 1:26 PM, Bob Kerns <r...@acm.org> wrote:

> > >



Other Threads

1. open context menu for a specific item of the list

Hi and thanks for the reply.

To be honest I had this idea myself, but I didn't know what to pass as
parameters to this method:

                      onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenuInfo menuInfo)

any ideas??







--~--~---------~--~----~------------~-------~--~----~

2. Boot up error- porting android to imx31 (android version 1.5)

Hi all,
I am trying to port android 1.5 version to my imx-31 borad. I have
successfully ported till 1.1 version in my board without any issue.
This time i am building the RFS from the source code rather than
pulling the RFS from the emulator. Please help me if any one come
across the following error:

D/AndroidRuntime(   27): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime(   27): CheckJNI is ON
I/dalvikvm(   27): DexOpt: source file mod time mismatch (3aae8f72 vs
3aee9431)
W/dalvikvm(   27): Cached DEX '/system/framework/core.jar' (/data/
dalvik-cache/sys...@framework@core....@classes.dex) is stale and not
writable
I/dalvikvm(   27): Unable to open or create cache for /system/
framework/core.jar
D/dalvikvm(   27): Failed on '/system/framework/core.jar' (boot=1)
D/dalvikvm(   27): VM cleaning up
D/dalvikvm(   27): LinearAlloc 0x0 used 4100 of 4194304 (0%)
W/dalvikvm(   27): JNI_CreateJavaVM failed
E/AndroidRuntime(   27): JNI_CreateJavaVM failed
I/        (   28): ServiceManager: 0xac38
W/AudioHardwareInterface(   28): Using stubbed audio hardware. No
sound will be produced.
I/AudioFlinger(   28): AudioFlinger's thread ready to run for output 0
I/CameraService(   28): CameraService started: pid=28
D/AndroidRuntime(   39):

The above is the logcat output.
I have build android from the source code downloaded from the
repository. And copied the file system from the "out/target/product/
generic/" path.
The procedure i followed is as follows:

[r...@localhost]# cd /opt
[r...@localhost]# mkdir my_repo
[r...@localhost]# cd my_repo
[r...@localhost]# curl http://android.git.kernel.org/repo > /bin/repo
[r...@localhost]# chmod a+x /bin/repo
[r...@localhost]# repo init -u 
git://android.git.kernel.org/platform/manifest.git
[r...@localhost]# repo sync

I got the source and then.
[r...@localhost]# export PATH=<jdl path>:$PATH
[r...@localhost]# make TARGET_ARCH=arm
build/core/product_config.mk:261: WARNING: adding test OTA key
============================================
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=
============================================
build/core/copy_headers.mk:15: warning: overriding commands for target
`out/target/product/generic/obj/include/libpv/getactualaacconfig.h'
build/core/copy_headers.mk:15: warning: ignoring old commands for
target `out/target/product/generic/obj/include/libpv/
getactualaacconfig.h'
make: execvp: /bin/bash: Argument list too long
Install: out/target/product/generic/system/app/Mms.apk
---- here i skipped lot of line -----

[r...@localhost]# ls out/target/product/generic/
android-info.txt  clean_steps.mk  data  installed-files.txt  obj
previous_build_config.mk
ramdisk.img  root  symbols  system  system.img  userdata.img

I trying to copy the filesystem to my SD card (card is partitioned in
2, sdc1 and sdc2 and i am copying the RFS to sda1 and the format is
ext3).

[r...@localhost]# mount /dev/sdc1 /mnt/sdcard1

[r...@localhost]# mkdir /opt/android_RFS_1.5

[r...@localhost]# cp -a ramdisk.img /opt/android_RFS_1.5

[r...@localhost]# cp -a system.img /opt/android_RFS_1.5

[r...@localhost]# cp -a userdata.img /opt/android_RFS_1.5

[r...@localhost]# cp -a system /opt/android_RFS_1.5

[r...@localhost]# cp -a data /opt/android_RFS_1.5

[r...@localhost]# cp -a root /opt/android_RFS_1.5

[r...@localhost]# cd /opt/android_RFS_1.5

[r...@localhost]# gzip -cd ramdisk.img > ramdisk

[r...@localhost]# cpio -iv -F ramdisk

Since i could not mount and extract system.img and userdata.img, i
have extracted data and system folders from the running emulator by
using adb.

[r...@localhost]# cp -a ./* /mnt/sdcard1

[r...@localhost]# sync

[r...@localhost]# umount /dev/sdc1

I have put the sdcard to my target board and booted up, the LCD
display is showing Android and it hangs and when i check the logcat
output the above error i could get.

Please advice me what the wrong step i am doing. And if any of you
came across the above error please advice me how to fix the same. Also
is there any links or mail threads which i can refer to.

Thank you.

With regds,
Shyjumon N

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. How can I see all comments on my app?

4. msm nand oob error

5. Where to buy a ADP1 Backplate/Battery Cover (with the Android robots)

6. Speech Codec Support for Android

7. Error in Repo Initialisation