我想延長GoogleApiClient.ConnectionCallbacks(),但要得到一個錯誤的ClassNotFoundException在NativeScript使用.extend()
`java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.sampleGroceries/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
Error calling module function
Error: java.lang.ClassNotFoundException: com.google.android.gms.common.api.GoogleApiClient_ConnectionCallbacks java.lang.Class.classForName(Native Method) java.lang.Class.forName(Class.java:324) java.lang.Class.forName(Class.java:285) com.tns.DexFactory.generateDex(DexFactory.java:262) com.tns.DexFactory.resolveClass(DexFactory.java:120) com.tns.ClassResolver.resolveClass(ClassResolver.java:45)
`
我相應的代碼是
var GoogleApiClient = com.google.android.gms.common.api.GoogleApiClient;
var myConnectionCallbacks = GoogleApiClient.ConnectionCallbacks.extend({
onConnected: function(connectionHint){
var MessageListener = MessageListener.extend({
onFound: function(message){
Log.d("MESSAGE", "Found message :) ");
},
onLost: function(message){
Log.d("MESSAGE", "Lost message :(");
}
});
var mMessageListener = new MessageListener();
},
onConnectionSuspended: function(){}
});
var MessagesOptionsBuilder = new com.google.android.gms.nearby.messages.MessagesOptions.Builder().setPermissions(NearbyPermissions.BLE).build();
var test = new GoogleApiClient.Builder(context).addApi(Nearby.MESSAGES_API, MessagesOptionsBuilder);
test.addConnectionCallbacks(new myConnectionCallbacks(this));
也許我誤解了Docs? https://docs.nativescript.org/runtimes/android/generator/extend-class-interface
編輯:爲什麼在GoogleApiClient之後的錯誤日誌中有下劃線?
任何建議我做錯了什麼?
我應該學會如何閱讀,謝謝! :) –