0

I am trying to build a RecyclerView sample with IntelliJ IDEA, but it gives me this error:

Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

There are two similar questions (1, 2), both of which recommend to set JAVA_HOME to Java 8. In my case, this doesn't help.

JAVA_HOME set to C:..\jdk1.8.0_181\
Symlinks in C:..\javapath\ lead to corresponding *.exe files.
SDK set to 1.8

UPD

Updated minSDKVersion to 17 and Java version to 8 in module build.gradle.

There was several JDK and Android API Platforms in project settings. Removed unused.

Now it builds succesfully, but crashes on the start.

Stacktrace:

07-28 06:16:11.994 7337-7337/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.recyclerview, PID: 7337
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.recyclerview/com.example.android.recyclerview.MainActivity}: java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to android.app.Activity
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassCastException: android.support.v7.widget.TintContextWrapper cannot be cast to android.app.Activity
    at com.example.android.common.logger.LogView.println(LogView.java:95)
    at com.example.android.common.logger.MessageOnlyLogFilter.println(MessageOnlyLogFilter.java:42)
    at com.example.android.common.logger.LogWrapper.println(LogWrapper.java:72)
    at com.example.android.common.logger.Log.println(Log.java:66)
    at com.example.android.common.logger.Log.i(Log.java:136)
    at com.example.android.common.logger.Log.i(Log.java:146)
    at com.example.android.recyclerview.MainActivity.initializeLogging(MainActivity.java:108)
    at com.example.android.common.activities.SampleActivityBase.onStart(SampleActivityBase.java:40)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
    at android.app.Activity.performStart(Activity.java:5241)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
    at android.app.ActivityThread.access$800(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5017) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    at dalvik.system.NativeStart.main(Native Method)

UPD 2

Fixed that as described here. Works like a charm.

Kirill Smirnov
  • 131
  • 2
  • 12

2 Answers2

0

If you are able to build the project successfully, go to the project, delete the directory called .idea, delete the file .iml. Reimport the project in Idea by going to the File > New > Project from Existing Sources. Hope it will help you to solve the issue.

Sambit
  • 7,625
  • 7
  • 34
  • 65
0

That was the compatability problem.

Removing unused JDK and SDK from IntelliJ project and updating classes versions and calls solved the first part of the problem.

To work correctly the project must have only JDK and SDK specified in module build.gradle.

Also there was compatability error with getContext(). Fixed that as described here.

Submitted pull request with code changes here.

Kirill Smirnov
  • 131
  • 2
  • 12