Java.lang.NullPointerException (no error message)

I know that this question of mine was asked many times, and I completed most of the answers, but none of them helped me. So this is my problem, whenever I synchronize my project, it always fails. Here's what the gradle console looks like:

Tasks: [: app: generateDebugSources ,: app: generateDebugAndroidTestSources ,: application: mockableAndroidJar ,: Application: prepareDebugUnitTestDependencies]

On-demand configuration is an incubation function. Incremental java compilation is an incubation feature .: application: preBuild UP-TO-DATE: app: preDebugBuild UP-TO-DATE: application: checkDebugManifest: app: preReleaseBuild UP-TO-DATE: Application: prepareComAndroidSupportAnimatedVectorDrawable2420Library UP-TO prepareComAndroidSupportAppcompatV72420Library UP-tO-DATE: application: prepareComAndroidSupportDesign2420Library UP-tO-DATE: app: prepareComAndroidSupportMediarouterV72300Library UP-tO-DATE: application: prepareComAndroidSupportRecyclerviewV72420Library UP-tO-DATE: app: prepareComAndroidSupportSupportCompat2420Library UP-to-DATE: app: prepareComAndroidSupportSupportCoreUi2420Library UP-TO- DATE: app: prepareComAndroidSupportSupportCoreUtils2420Library UP-TO-DATE: app: prepareComAndroidSupportSupportFragment2420Library UP-TO-DATE: app: prepareComAndroidSupportSupportMediaCompat2420Libr ary UP-TO-DATE: app: prepareComAndroidSupportSupportV42420Library UP-TO-DATE: Appendix: prepareComAndroidSupportSupportVectorDrawable2420Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServices940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesAds940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesAdsLite940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesAnalytics940Library Timeliness: Appendix : prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl940Library TEMPORARY: Application: prepareComGoogleAndroidGmsPlayServicesAppindexing940Library TEMPORARY: Application: prepareComGoogleAndroidGmsPlaySourceLibraryPlayer reComGoogleAndroidGmsPlayServicesAuthBase940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesBase940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesBasement940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesCast940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesCastFramework940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesClearcut940Library Timeliness: Appendix: prepareComGoogleAndroidGmsPlayServicesContextmanager940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesDrive940Library TIMELY: Application: prepareComGoogleAndroidGmsPlayServicesFitness940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesGames940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPla yServicesGass940Library UP-TO-DATE: application: prepareComGoogleAndroidGmsPlayServicesGcm940Library TIMELY: app: prepareComGoogleAndroidGmsPlayServicesIdentity940Library FAILURE: Build failed with exception.

  • What went wrong: java.lang.NullPointerException (no error message)

  • Try it: run with the -stacktrace option to get a stack trace. Run with the -info or --debug option to get more log output.

STRICTLY MALFUNCTIONAL

Total time: 7,518 sec.

And these are my addictions

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:design:24.2.0' compile 'com.google.android.gms:play-services:9.4.0' testCompile 'junit:junit:4.12' compile 'com.google.android.gms:play-services-location:9.4.0' compile 'com.google.android.gms:play-services-appindexing:9.4.0' compile 'com.google.firebase:firebase-messaging:9.2.0' compile 'com.google.firebase:firebase-database:9.0.2' compile 'com.firebase:firebase-client-android:2.4.0' compile 'com.google.firebase:firebase-core:9.4.0' } apply plugin: 'com.google.gms.google-services' 

How to solve a problem?

+72
android build.gradle gradle
Aug 27 '16 at 17:06
source share
10 answers

I deleted the .gradle folder from the project and was able to restore it again.

NB: Make a backup, just in case.

+183
Sep 01 '16 at 21:54
source share

This problem occurs when the system reboots suddenly, and then the gradle file is damaged. and this damaged file is cached, so we need to delete this file from your project

 your_project_path/.gradle/2.14.1/taskArtifacts 

It will be generated again.

Then restart android studio and recompile the project.

source: https://code.google.com/p/android/issues/detail?id=220741#c13

It worked for me.

+28
Oct 07 '16 at 2:53 on
source share

If you still have this problem, even after deleting the .gradle folder in your project path, as suggested above , kill all the Java processes running in the task manager and try updating Android Studio .

I was in the same situation, but now it works fine.

Hope this helps!

+3
May 14 '17 at 1:48 p.m.
source share

The problem is probably related to the gradle.properties file. If you ./gradlew tasks in the terminal ./gradlew tasks , you see the error you specified, but ./gradlew tasks --info show more detailed information about the error. For me, in all my projects, this was the same error message:

 Java home is different. Wanted: DefaultDaemonContext[uid=null,javaHome=/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home,daemonRegistryDir=/Users/christian/.gradle/daemon,pid=66346,idleTimeout=null,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant] Actual: DefaultDaemonContext[uid=4bf81505-0eab-4f50-859a-8c9c616b97e5,javaHome=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home,daemonRegistryDir=/Users/christian/.gradle/daemon,pid=65018,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant] 

Solution: (no need to edit .bash_profile or lower degrees or delete gradle.folder).

  • Add org.gradle.java.home=path to gradle.properties. where path is the Android Studio Java path (the actual java address specified in --info ). For me, this is /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home , for you the path may be different.

This is what my gradle.properties file looks like after the change:

 org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home org.gradle.daemon=true 

Notes . The space between โ€œAndroid Studioโ€ in the path is intentional; it does not work if the underscore is used. Escape characters \ allowed but not needed: ...Android\ Studio.app/Contents/jre....

I also included a runner to create the daemon, but was not needed to complete its tasks. If your null pointer error is different, use --info to point you in the right direction.

I'm runing:

 Android Studio 3.1.4 (on a Mac 10.13) java version "10" classpath 'com.android.tools.build:gradle:3.1.4' (dependency) 

Hope this helps someone!

+1
Sep 23 '18 at 1:42
source share

I have the same problem when Java version 1.9

 jenv use java 1.8 

the whole problem is resolved.

+1
Feb 20 '19 at 8:30
source share
 compile 'com.google.android.gms:play-services-location:9.4.0' compile 'com.google.android.gms:play-services-appindexing:9.4.0' compile 'com.google.firebase:firebase-messaging:9.2.0' compile 'com.google.firebase:firebase-database:9.0.2' 

Not sure if this is a criminal, but you are pretty confused with the versions used here. Try using the latest versions or at least the same for all related components.

This tool can help you stay in sync in the future: https://github.com/ben-manes/gradle-versions-plugin

0
Aug 27 '16 at 17:15
source share

I had a similar problem when importing firebase into my project. First of all, make sure that you completed the training steps correctly and imported the provided .json file into the correct directory.

In addition, since firebase v9.0 was embedded in Google Play services, so that firebase works correctly, make sure that Google play services are updated on the device under test,

I also found this answer helpful in resolving my issue https://stackoverflow.com/a/464829/

0
Aug 27 '16 at 17:17
source share

Remove the lines from the dependencies below, because you are already compiling the game services dependency

  compile 'com.google.android.gms:play-services-location:9.4.0' compile 'com.google.android.gms:play-services-appindexing:9.4.0' 
0
Aug 27 '16 at 17:32
source share

Check out app/build.gradle . My problem was ' addicted.

0
Sep 18 '17 at 6:30
source share

I was getting NPE due to jdk version, downgrading from 11 to 8 solved this problem

Remove JDK 11

sudo rm -rf / Library / Java / JavaVirtualMachines / jdk-11.0.2.jdk

 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptDebugKotlin'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110) Caused by: java.lang.NullPointerException at org.gradle.workers.internal.DefaultWorkerExecutor$2.transform(DefaultWorkerExecutor.java:164) at org.gradle.workers.internal.DefaultWorkerExecutor$2.transform(DefaultWorkerExecutor.java:161) at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:204) at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:187) at org.gradle.util.CollectionUtils.collect(CollectionUtils.java:191) at org.gradle.workers.internal.DefaultWorkerExecutor.getDaemonForkOptions(DefaultWorkerExecutor.java:161) at org.gradle.workers.internal.DefaultWorkerExecutor.submit(DefaultWorkerExecutor.java:96) at org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask.compile(KaptWithoutKotlincTask.kt:75) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
0
Jan 24 '19 at 14:05
source share



All Articles