0

I am currently learning to develop apps for Android-based devices, and I have a pretty decent hold on Java, so learning hasn't been too challenging for me. However, I am lazy, and I don't want to import each individual Android class that I need. In one of my .java files, if I was to type:

import android.*;

It would compile fine. However, if I was to type:

public class example extends Activity{...}

Below the former piece of code, Eclipse/ADT still tells me I need to import the android.app.Activity class. So, is there another way I could import all the android classes in order for me to save the time of importing each one individually?

If not, I'll be a good sport and get over it, but it would be really convenient, nonetheless.

J-Play
  • 29
  • 1
  • 6
  • Please read [Why is using a wild card with a java import statement bad](http://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad). Furthermore, use the fix imports shortcut, it will do it for you. – nhaarman May 13 '14 at 16:16
  • I read the piece you gave me, and I will take your help. Thank you for that. – J-Play May 13 '14 at 16:36

2 Answers2

2

So, is there another way I could import all the android classes in order for me to save the time of importing each one individually?

import android.*; will only import classes and interfaces that are directly in the android package. To import all classes/interfaces in android.app, use import android.app.*;.

Bear in mind that Eclipse/ADT provides multiple ways of adding the imports for you, such as Ctrl-Shift-O to resolve all missing imports.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

You can also use Eclipse/Adt setting "Organize Imports" in Java ->Editor -> Save Actions to allow Eclipse organize your imports on save. Very useful. Also you can customize the setting in Java -> Code Style -> Organize Imports.

fpanizza
  • 1,589
  • 1
  • 8
  • 15