Invalid JSON with use Fabric SDK - android

I use this code and catch error:
// I I did everything according to the manual
loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Result<TwitterSession> result1 = result;
}
#Override
public void failure(TwitterException exception) {
exception.printStackTrace(); // I catch this exception
}
});
And this my logs:
01-26 12:39:10.258 32298-32298/com.DriverNotes.AndroidMobileClient E/Twitter﹕ Invalid json: <?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>Desktop applications only support the oauth_callback value 'oob'</error>
<request>/oauth/request_token</request>
</hash>
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
at com.google.gson.JsonParser.parse(JsonParser.java:65)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
at com.twitter.sdk.android.core.TwitterApiException.parseErrorCode(TwitterApiException.java:107)
at com.twitter.sdk.android.core.TwitterApiException.readErrorCode(TwitterApiException.java:96)
at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:43)
at com.twitter.sdk.android.core.TwitterApiException.convert(TwitterApiException.java:81)
at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
P.S. I hope to have given enough information about the problem

From the error, it looks like your Twitter application may need some additional information in order to work properly. Take a look at this:
https://twittercommunity.com/t/desktop-applications-only-support-the-oauth-callback-value-oob-oauth-request-token/252/2

If it's still relevant - I had the same problem and the solution was to set the redirect_url field in the app web page.
and also you MUST uncheck the textbox:
"Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url)"

Related

Multiple enqueue in retrofit causing out of memory error?

Am doing my project using retrofit2. When my Call goes on failure i repeat same call again.Repeation of this call made my app to force close.
When i look on log i got error log, which is given below. I felt this is caused by multiple enqueue to same Call. So i did that before enqueus i called cancel. But its not working. getting same force close.
FATAL EXCEPTION: main
Process: com.SocialMob, PID: 27846
java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
at java.lang.VMThread.create(Native Method)
at java.lang.Thread.start(Thread.java:1029)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
at okhttp3.Dispatcher.enqueue(Dispatcher.java:112)
at okhttp3.RealCall.enqueue(RealCall.java:78)
at okhttp3.RealCall.enqueue(RealCall.java:70)
at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:104)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.enqueue(ExecutorCallAdapterFactory.java:58)
at com.SocialMob.Activities.SplashActivity.VersionCheck(SplashActivity.java:184)
at com.SocialMob.Activities.SplashActivity.access$500(SplashActivity.java:38)
at com.SocialMob.Activities.SplashActivity$1.onFailure(SplashActivity.java:177)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$2.run(ExecutorCallAdapterFactory.java:75)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Thanks in advance.
You should avoid that approach, as it would make it a recursive call. Instead you should check the cause in the failure function first and then retry. Also fix the number of retry times.
I am using Retrofit 2.0.2, and i have this tag in my manifest file:
android:largeHeap="true"
I am retrying on failure like this:
#Override
public void onFailure(Call<AudioResponse> call, Throwable error) {
loading.setVisibility(View.GONE);
if (mAdapter.getItemCount() == 0) {
SetErrorContent();
}
Log.e("Error", error.getMessage() + "");
call.cancel();
call.clone().enqueue(this);
}
It is not crashing.Give it a try.

Android KITKAT (4.0.3 API 15) View.startDrag() throws NullPointerException

View.startDrag throws NPE and this is happening to me for Android API 15 but not API 22.
This issue is very easy to reproduce. Open Android Studio, create a template project with one blank activity using API 15. Adding the following logic to the floating action button:
fab.setOnLongClickListener(
new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
v.startDrag(ClipData.newPlainText("", ""), new View.DragShadowBuilder(v), null, 0);
return true;
}
}
);
The stacktrace for the error is the following:
E/View: Unable to initiate drag
java.lang.NullPointerException
at android.view.Surface.lockCanvas(Surface.java:77)
at android.view.View.startDrag(View.java:13869)
at test.dragdroptest.MainActivity$2.onLongClick(MainActivity.java:59)
at android.view.View.performLongClick(View.java:3827)
at android.view.View$CheckForLongPress.run(View.java:14571)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Not sure what I did wrong here. I have been fighting this issue for two days and there is not much resource online about this. I cannot believe no one else had ran into the same issue...
Apparently, it only happens on the device I used for testing but not from emulator with the same API level. I guess there is no way I can get away from this issue :(

Security Exception with AccountManager

I'd like to create an account in my Android app programatically.
I've read thing about the AccountManager class and tried to implement it.
Unfortunately, I get a SecurityException when I try to add the account.
Account account = new Account(user.getLogin(), 'packageName');
The thing I don't understand is about the type (in the second parameter).
What do I've to put in second parameter in order to make my code working.
Moreover, I'd like to know if I can add an acount simply with theses lines of code, or should I use a service like many example show ?
Thanks
EDIT - Full Exception Message
java.lang.SecurityException: caller uid 10047 is different than the authenticator's uid
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.accounts.IAccountManager$Stub$Proxy.addAccount(IAccountManager.java:580)
at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:565)
at fr.opendev.elisaG.activity.LoginActivity.isUserAuthorized(LoginActivity.java:113)
at fr.opendev.elisaG.activity.LoginActivity.access$500(LoginActivity.java:27)
at fr.opendev.elisaG.activity.LoginActivity$1.onClick(LoginActivity.java:70)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16964)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

java.lang.NumberFormatException (parse.Int)

An app published on market has an error:
java.lang.NumberFormatException
below the stack.
Is the cause this code?
fade = Integer.parseInt(ListPreference);
I see "OTHER" devices has affected by this crash. Any idea?
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Notify}: java.lang.NumberFormatException: unable to parse '' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3768)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: unable to parse '' as integer
at java.lang.Integer.parseInt(Integer.java:362)
at java.lang.Integer.parseInt(Integer.java:332)
at com.example.app.Notify.onCreate(Notify.java:33)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more
java.lang.NumberFormatException: unable to parse '' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
==> it seems you are trying to parse an empty string. You should include the parsing operation in a try/catch block and deal with malformed inputs.
as in log :
NumberFormatException: unable to parse '' as integer
you are trying to parse space to integer . before parsing string value to Integer check for null or empty
Actually, There is any symbol or character happen in String ListPreference,
Its better to Handle this exception.
try {
fade = Integer.parseInt(ListPreference);
} catch (NumberFormatException e) {
Log.e("Exception",e.toString());
}
Update:
Look at the Jakarta Commons :
NumberUtils.isNumber()
This can be used to check most whether a given String is a number.
Also before using String ListPreference just removed white space from it using trim().
Using ListPreference.trim() and also check the length of ListPreference whether length is greater than 1 or not.
like, ListPreference.length() > 1

Arrayadapter.getcount null point exception

I am getting the following stack trace (below is a complete copy) , this gives me little or no indication as to where in a massive application it is when going wrong and user feedback is nothing beyond "It crashed".
Is there anything I can do to pinpoint this more ?
java.lang.NullPointerException at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:291)
at android.widget.AdapterView.checkFocus(AdapterView.java:689)
at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:43)
at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:54)
at android.widget.ArrayAdapter$ArrayFilter.publishResults(ArrayAdapter.java:469)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Look at the code for ArrayAdapter.getCount():
/**
* {#inheritDoc}
*/
public int getCount() {
return mObjects.size();
}
Clearly mObjects is null, i.e. your ListView or other AdapterView-derived type is trying to use the adapter before you've initialized it with it's data.
What you could do is putting debug information before every call to getCount() using the Log class
Log.d("tag", "Trying to get count on line 50 class Test");
then open logcat and find the last entry of this log before the error occures. Then you have the right location of the crash.

Categories

Resources