I am trying to develop a nativescript plugin to perform some functionality with the Azure SDK. The docs for the SDK show below:
So I have added the following function to my plugin:
MobileServiceUser.newUser = function (userId, client) {
var userObject = com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId); // causing the error
client.setCurrentUser(userObject);
};
UserId is a string.
However, the top line throws the error:
JS: Error: Trying to link invalid 'this' to a Java object
I have a full repo showing the minimal implimentation to create this issue on Github.
I would be really grateful of any suggestions how to fix this.
This answer is a little late but I recently ran into this issue myself. Hopefully this answer helps someone in the future!
The error is a bit plain but if you take a look at the code source, you'll see that it's actually telling you that you cannot link a variable to the Object/Class itself as a reference:
MobileServiceUser.newUser = function (userId, client) {
var userObject = com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId);
};
When you want to instantiate a class, you need to use the keyword new to signify this action. Without new listed before the class constructor call, the program just sees that you're making a direct link between userObject and the class itself. This should fix your problem:
var userObject = new com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId);
Cheers
~Px
Related
Hello I am trying to update stripe but when I have to call PaymentSessionConfig my code blocks because the companion of the PaymentSessionConfig class is in private, I cannot modify the class because it is in read only, here is the line :
mPaymentSession = PaymentSession (activity = summaryActivity, config = PaymentSessionConfig)
and the error message I have :
Cannot access 'Companion': it is private in 'PaymentSessionConfig'
Type mismatch.
Required:
PaymentSessionConfig
Found:
PaymentSessionConfig.Companion
Can you share the details of what versions of the SDK you're updating from and to? The migration docs cover a lot of details changes for various versions.
Is it possible you mean to reference some paymentSessionConfig, or what is your config here?
See this example implementation using the PaymentSessionConfig.Builder() (github)
I am writing an app and just redo it from a youtube video to get back into app writing.
All this Kotlin is new to me as it didn't exist last time I programmed some apps.
When creating the new App I chose Kotlin instead of java.
Now I want to create a Constants class with a companion:
public class Constants {
companion object {
const BASE_URL = "https://whatever.com"
}
}
But too many errors are shown:Shown errors
companion: cannot resolve
object: missing ;
const: unexpected token
BASE_URL: cannot resolve
string: missing ;
Furthermore, I have created a new class which should be a data class, but it doesn't recognize it as well:
data class
I did install the KOTLIN plugins but it didn't help.
I'm trying to add some android native unit tests for a capacitor plugin I created.
The problem is that the method expects to get a PluginCall object as a param. In iOS it's pretty straightforward. for example:
func test()
{
let data = "madness? THIS. IS. DATA!!!!! ~Leonidas I, King of Data, around 480 BCE"
let plugin = Plugin()
let call = CAPPluginCall(callbackId: "test", options: [
"data": data
], success: { (result, call) in
let resultValue = result?.data["data"] as? Data
XCTAssert(resultValue != nil)
}, error: { (err) in
XCTFail("Error shouldn't have been called")
})
plugin.doSomethingCool(call!)
}
Pretty simple stuff really.
Trying to do the same thing for android, doesn't work quite well.
To instantiate a new PluginCall object I have to pass to the constructor a MessageHandler object, and to instantiate a MessageHandler object I have to pass a Bridge object, to instantiate a bridge object, I have to pass a PluginManager object that the compiler doesn't even recognise. Apparently an impossible task.
Of course I can always just replace the PluginCall param with the actual data, but I want to have a full test coverage for my plugin and not omit huge parts of it just so I can test it. Trying to search this problem online yielded no results, even the official docs doesn't say anything about it, so I turn to SO. Has anyone done something like this before and can point me in the right direction?
TL;DR
How can I create android native unit tests for a capacitor plugin?
Thanks :)
Ok so i have an app than had a Coin realm object. I am now upgrading my app, and adding multiple new fields to the existing Coin object. So far so good, but how do i migrate a LinkingObject, RealmResults type. linkedPortfolioCoins is what i want to migrate
public class Coin extends RealmObject {
//a bunch of other fields here
#LinkingObjects("coin")
private final RealmResults<PortfolioCoin> linkedPortfolioCoins = null;
}
Also, There is only
.addRealmListField
Which i assume will be ok instead of RealmResults, but how do i make it a LinkingObject to Coin.
The error im getting is
Caused by: io.realm.exceptions.RealmMigrationNeededException: Field count is more than expected - expected 18 but was 19
Ok just to help anyone in future. It appears you dont have to migrate linking objects. Got it working by just not migrating the linkedPortfolioCoins and leaving it out. That would also explain my error :)
Hellow , i am a student and i am working on a project. It is a Xamarin native project (cross-platform). I Use MVVM. This was working perfect when i was using 1 shared project and my 3other projects (android,iOS,winphone). Now I have different projects for my shared code.
-Appname.Repositories
-Appname.Services
-Appname.Viewmodel
Now the problem is that when i start my app using an constructor in my viewmodel with an interface he is given me the next error :
//Constructor
public LoginViewModel(IMvxMessenger messenger, IUserDataService userDataService) : base(messenger)
{
_userDataService = userDataService;
}
Error:
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type C_Tracker.Mobile.Domain.ViewModel.LoginViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
InnerException :
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to resolve parameter for parameter userDataService of type IUserDataService
But when i use a constructor without this interface it is working.
public LoginViewModel(IMvxMessenger messenger) : base(messenger)
{
}
Please help me.
Probably you forgot about Dependencies Injection.
Add to Setup.cs something like this Mvx.RegisterType<IUserDataService, UserDataService>();
For more information about ServiceLocator please check https://github.com/MvvmCross/MvvmCross/wiki/service-location-and-inversion-of-control