Android Question How to use JavaObject InitializeArray correctly ?

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi all,

I was trying to use JTwitter for android and started by the following code

B4X:
    Dim atl  As JavaObject
    atl.InitializeArray("winterwell.jtwitter.android.AndroidTwitterLogin" ,Array (Activity,conKey,conSecret,cb))

Here is the Java Example I am following :

B4X:
 AndroidTwitterLogin atl = new AndroidTwitterLogin(myApp,
                                MY_TWITTER_KEY,MY_TWITTER_SECRET,MY_TWITTER_CALLBACK) {                               

        protected void onSuccess(Twitter jtwitter, String[] tokens) {
                jtwitter.setStatus("I can now post to Twitter!");
                // Recommended: store tokens in your app for future use
                // with the constructor OAuthSignpostClient(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret)
        }
};
atl.run();

but unfortunately I got the following error

B4X:
java.lang.IllegalArgumentException: Array has incompatible type: class [Lwinterwell.jtwitter.android.AndroidTwitterLogin;

I think I must set type of each argument but I could not get that working.
I need your help .

Thanks in advance
 

stevel05

Expert
Licensed User
Longtime User
Yes, you will have to make sure that the variables you are passing match those required by AndroidTwitterLogin.

Do you have the documentation? What should the signature be?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Activity in B4a is a wrapper, you need to pass the actual Activity which you can get using the reflection library:

B4X:
Dim R As Reflector
atl.InitializeArray("winterwell.jtwitter.android.AndroidTwitterLogin" ,Array (R.GetActivity,conKey,conSecret,cb))
The other three variables should be Strings.

I haven't tried it but I think that should work.
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Activity in B4a is a wrapper, you need to pass the actual Activity which you can get using the reflection library:

B4X:
Dim R As Reflector
atl.InitializeArray("winterwell.jtwitter.android.AndroidTwitterLogin" ,Array (R.GetActivity,conKey,conSecret,cb))
The other three variables should be Strings.

I haven't tried it but I think that should work.

Thanks a lot Stevel but unfortunately , the same error .
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you zip and post your project so I can try a few things?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Why are you using InitializeArray? You will need to use InitializeNewInstance to get the AndroidTwitterLogin object. But you will still need to use the Reflector to get the activity.

An array would have to contain all objects of the same class.
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Why are you using InitializeArray? You will need to use InitializeNewInstance to get the AndroidTwitterLogin object. But you will still need to use the Reflector to get the activity.

An array would have to contain all objects of the same class.

I am not sure I understood you well but I changed to InitializeNewInstance and got the error :

B4X:
java.lang.InstantiationException: can't instantiate class winterwell.jtwitter.android.AndroidTwitterLogin


You cannot call this API with JavaObject. It is not possible to subclass an abstract class (or concrete class) with reflection.

Thanks Erel .
So is there any way to use this library ?
 
Upvote 0
Top