- error NotificationIntentService has no zero argument constructor #2
- Comments
- andrew19881123 commented Sep 14, 2016
- WinMinTun commented Sep 21, 2016
- petekanev commented Sep 21, 2016 •
- WinMinTun commented Sep 21, 2016 •
- petekanev commented Sep 21, 2016
- WinMinTun commented Sep 22, 2016
- ivanwitzke commented Dec 5, 2016 •
- samuelt1 commented Dec 29, 2016 •
- petekanev commented Jan 21, 2017
- pacear10 commented Jan 24, 2017
- petekanev commented Jan 24, 2017 •
error NotificationIntentService has no zero argument constructor #2
Comments
andrew19881123 commented Sep 14, 2016
I saw the note on the nativescript blog
IntentService’s implementation needs to use a constructor that takes no arguments, but that currently is not possible through Java.
but how do I solve the problem to make this app works?
The text was updated successfully, but these errors were encountered:
WinMinTun commented Sep 21, 2016
@andrew19881123 @slavchev I m having the same problem and cannot move passed. Pls help!!
petekanev commented Sep 21, 2016 •
With version 2.2.0 of the android runtime you can open the generated .java file and remove the extra piece of code yourself. With the recent update to the binding generator in 2.3.0 .java files are no longer generated and that can’t be done.
WinMinTun commented Sep 21, 2016 •
Yes I see it there. But the problem is my edited code gets overwritten when tns run android .
- Generated .java file cannot be edited — overwritten when build and run. I just need to add
public NotificationIntentService() < this("NotificationIntentService"); >in java. How can I do that to the JS? - And also another problem is that after platform removed, can no longer re-generate .java files. I have already built and run a number of times and still not re-generated.
petekanev commented Sep 21, 2016
@WinMinTun regarding 1) — the lack of empty constructor is JVM’s fault, but we normally rewrite generated classes. You may have to disable the binding generator after having generated the java class and editing it. To do that — open platforms/android/build.gradle and comment out setProperties.finalizedBy(«asbg:generateBindings»)
2) — if you are using 2.2 .java should be generated in src/java , in 2.3 the runtime works with dexes that can not be edited.
WinMinTun commented Sep 22, 2016
@Pip3r4o Thanks a lot for the details. It works now for 2.2.
ivanwitzke commented Dec 5, 2016 •
Any solution for this on 2.3+ ?
I’m using «tns-core-modules 2.4.1» and «tns-android 2.4.1» and I need to implement a background sync service for the app I’m developing. (Must work even when the app is closed. )
samuelt1 commented Dec 29, 2016 •
i am having the same problem. I also noticed that this sample project has a few extra files that my project does not have.
platforms/android/src/main/java/com/tns/broadcastreceivers
platforms/android/src/main/java/com/tns/notifications
platforms/android/src/main/java/com/tns/activities
did you manually add these files?
are these the location of the files that @WinMinTun edited to make it work?
are these what fixed the no argument constructor?
I downloaded the code from this repository, and it works fine, but if I remove platforms then i get the no zero argument constructor error, so i think there is something i am not being told here.
what else do i need to add?
I added these files to my project, and it still does not work.
petekanev commented Jan 21, 2017
Project was cleaned up, and a fix applied in the form of a plugin. Feel free to test out the updated sample, and let me know how it works for you. Thanks!
pacear10 commented Jan 24, 2017
Today I am running the project for background services
But still throwing the same error, is there something that should be done to clone the project to take the changes that made the project to stop displaying the error message?
Thank you.
An uncaught Exception occurred on «main» thread. java.lang.RuntimeException: Unable to instantiate service com.tns.notifications.NotificationIntentService: java.lang.InstantiationException: can’t instantiate class com.tns.notifications.NotificationIntentService; no empty constructor at android.app.ActivityThread.handleCreateService(ActivityThread.java:2641) at android.app.ActivityThread.access$1600(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5227) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.InstantiationException: can’t instantiate class com.tns.notifications.NotificationIntentService; no empty constructor at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2638) . 10 more
petekanev commented Jan 24, 2017 •
@pacear10 From a freshly cloned project, it should be as simple as adding the android platform and running the project, the necessary dependencies should be downloaded, installed, then you’ll be good to go.
Источник