Closed vinayhfs closed 8 years ago
Same here...
Have you any thoughts about why this is happening? I've no experience with NativeScript and Angular.
I think it is the same problem that here.
In this case:
public show(msg: string, duration?: string): void {
duration = duration || 'short';
var Toast = require('nativescript-toast');
Toast.makeText(msg, duration).show();
}
The key is insert the 'require line' inside the method. It works for me.
I'm having the same issue on a customer project. Will take look at it next week
you can try to use the develop version:
tns plugin add nativescript-toast@next
Should be resolving this issue
can confirm that the latest dev build is working with angular
I tried use it with angular and got a error as (used Toast.makeText("Hello World", "long").show();) JS: ORIGINAL EXCEPTION: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResour ces()' on a null object reference JS: android.widget.Toast.(Toast.java:101)
JS: android.widget.Toast.makeText(Toast.java:250)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:861)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:726)
JS: com.tns.Runtime.callJSMethod(Runtime.java:712)
JS: com.tns.Runtime.callJSMethod(Runtime.java:693)
JS: com.tns.Runtime.callJSMethod(Runtime.java:683)
JS: com.tns.gen.android.view.View_OnClickListener.onClick(View_OnClickListen
er.java:11)
JS: android.view.View.performClick(View.java:4756)
JS: android.view.View$PerformClick.run(View.java:19749)
JS: android.os.Handler.handleCallback(Handler.java:739)
JS: android.os.Handler.dispatchMessage(Handler.java:95)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5221)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.ja
va:899)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
JS: ORIGINAL STACKTRACE:
JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'and
roid.content.res.Resources android.content.Context.getResources()' on a null obj
ect reference
JS: android.widget.Toast.(Toast.java:101)
JS: android.widget.Toast.makeText(Toast.java:250)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:861)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:726)
JS: com.tns.Runtime.callJSMethod(Runtime.java:712)
JS: com.tns.Runtime.callJSMethod(Runtime.java:693)
JS: com.tns.Runtime.callJSMethod(Runtime.java:683)
JS: com.tns.gen.android.view.View_OnClickListener.onClick(View_OnClickListen
er.java:11)
JS: android.view.View.performClick(View.java:4756)
JS: android.view.View$PerformClick.run(View.java:19749)
JS: android.os.Handler.handleCallback(Handler.java:739)
JS: android.os.Handler.dispatchMessage(Handler.java:95)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5221)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.ja
va:899)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
JS: at Error (native)
JS: at Object.makeText (/data/data/org.nativescript.NsAgTest/files/app/tns_m
odules/nativescript-toast/toast.js:13:18)
JS: at TestRouteComponent.showToast (/data/data/org.nativescript.NsAgTest/fi
les/app/pages/testroute.Component.js:10:15)
JS: at DebugAppView._View_TestRouteComponent0._handle_tap_9_0 (TestRouteComp
onent.template.js:124:28)
JS: at Object. (/data/data/org.nativescript.NsAgTest/files/app/tn
s_modules/@angular/core/src/linker/view.js:366:24)
JS: at ZoneDelegate.invoke (/data/data/org.nativescript.NsAgTest/files/app/t
ns_modules/zone.js/dist/zone-node.js:281:29)
JS: at Object.NgZoneImpl.inner.inner.fork.onInvoke (/data/data/org.nativescr
ipt.NsAgTest/files/app/tns_modules/@angular/core/src/zone/ng_zone_impl.js:46:41)
JS: at ZoneDelegate.invoke (/data/data/org.nativescript.NsAgTest/files/app/t ns_modules/zone.js/dist/zone-node.js:280:35) JS: at Zone.runGuarded (/data/data/org.nativescript.NsAgTest/files/app/tns_m odules/zone.js/dist/zone-node.js:188:48) JS: at Object.callback (/data/data/org.nativescript.NsAgTest/files/app/tns_m odules/zone.js/dist/zone-node.js:164:30) JS: ERROR CONTEXT: JS: [object Object] W/System.err(19324): com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(19324): com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java :861) W/System.err(19324): com.tns.Runtime.callJSMethodImpl(Runtime.java:726) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:712) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:693) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:683) W/System.err(19324): com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(19324): com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java :861) W/System.err(19324): com.tns.Runtime.callJSMethodImpl(Runtime.java:726) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:712) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:693) W/System.err(19324): com.tns.Runtime.callJSMethod(Runtime.java:683) W/System.err(19324): at com.tns.Runtime.callJSMethodNative(Native Method) W/System.err(19324): at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.ja va:861) W/System.err(19324): at com.tns.Runtime.callJSMethodImpl(Runtime.java:726) W/System.err(19324): at com.tns.Runtime.callJSMethod(Runtime.java:712) W/System.err(19324): at com.tns.Runtime.callJSMethod(Runtime.java:693) W/System.err(19324): at com.tns.Runtime.callJSMethod(Runtime.java:683)