10

I'm attempting to create a Handler thread in my application however Android Studio marks my text as red and will only attempt to import the java.util version of a handler and not the Android SDK version. When attempting to import manually I'm able to find the HandlerThread just fine but the normal handler import seems to be missing.

Any ideas why?

hoss
  • 2,430
  • 1
  • 27
  • 42
b1kjsh
  • 1,109
  • 2
  • 9
  • 21
  • those are part of the same jar. Probably you have misspelled the import – Blackbelt Jun 15 '13 at 07:29
  • Android Studio will auto complete the import for you. So if I was to type android.os. it would then complete the import for me. In the list it does not show "Handler" as an available object. – b1kjsh Jun 15 '13 at 07:32

6 Answers6

32

I had to add import android.os.*; before I could get the android.os.Handler object working in my class.

Community
  • 1
  • 1
b1kjsh
  • 1,109
  • 2
  • 9
  • 21
5

Just import android.os.Handler, no need to import everything in android.os

Peizhong Ju
  • 51
  • 1
  • 1
2

open : Settings -> Editor -> General -> Auto Import。

Exclude from Import

imyyq.star
  • 21
  • 2
1
import android.os.*;

solved the problem.

Rob
  • 26,989
  • 16
  • 82
  • 98
  • 1
    Welcome to SO. Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should [vote it up](https://stackoverflow.com/help/privileges/vote-up) once you have enough [reputation](https://stackoverflow.com/help/whats-reputation) – stelioslogothetis Jul 01 '17 at 15:25
0

Make sure that your Android SDK is added properly to Android studio. To do this go to File -> Project Structure and check the SDKs item under Platform Settings. Also make sure that you have selected a Project SDK under the Project item.

See the IntellJ documentation for more information.

free3dom
  • 18,729
  • 7
  • 52
  • 51
-1

It works because Android Studio and InteliJ usually import import android.os.Handler; instead of import android.os.Handler;

When you import the android version of Handler make sure you remove the Java version because the Java version is always compiled first over the Android version.

puma-lima
  • 17
  • 3