NullPointerException at SuggestionSpan - android

I am getting a NullPointerException at SuggestionSpan. (Stack trace included below). As the stack trace does not include any of my code, I have absolutely no idea where to start debugging.
The error can be reproduced whenever I press space (or select a word) while using an EditText. I tried multiple keyboards including the stock Android one but the same error appears.
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.text.style.SuggestionSpan.<init>(SuggestionSpan.java:128)
at android.text.style.SuggestionSpan.<init>(SuggestionSpan.java:101)
at android.widget.SpellChecker.createMisspelledSuggestionSpan(SpellChecker.java:392)
at android.widget.SpellChecker.onGetSuggestions(SpellChecker.java:300)
at android.view.textservice.SpellCheckerSession.handleOnGetSuggestionsMultiple(SpellCheckerSession.java:198)
at android.view.textservice.SpellCheckerSession.access$000(SpellCheckerSession.java:86)
at android.view.textservice.SpellCheckerSession$1.handleMessage(SpellCheckerSession.java:112)
at android.os.Handler.dispatchMessage(Handler.java:99)
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)
EDIT: I can only reproduce the error on my Nexus S with 4.0.3, but not on emulators with other OS versions. Weird.
EDIT 2: Strange thing happened! I just dragged an EditText into another activity and the same thing happens. No code is attached to it nor any XML changes made to it.

After days of investigation, it turns out that getResources().getConfiguration().locale is null. I am not sure if it is a problem specific to some versions of Android / some devices (mine is Nexus S running 4.0.3).
But I worked around this issue by checking in the constructor of the Activity (since the context given to the SuggestionSpan is my Activity) whether the locale is null, and then set it to the default one if it is.
// to prevent a weird bug where locale is null
Configuration config = getResources().getConfiguration();
if (config.locale == null)
config.locale = Locale.getDefault();
That's what I did. I am quite sure it's not the best way though. Anyone have any more ideas?

Related

Android: Occasional StackOverflowError on SharedPreferences.Editor.Commit in Emulator

I'm facing a weird issue where I am occasionally getting a StackOverflowError on calling SharedPreferences.Editor.Commit(). Problem occurs only sometimes and on Emulator only. If I rerun the app and call commit for the same value - everything is fine.
Seems rather random, and not something I ever saw on a physical device with the same code base. Seeing this on Pixel 3 API 29 Emulator image. Wondering if its an emulator issue.
Would like to know the cause for this error coming up randomly and what should be done about it?
Exception stack trace:
E/AndroidRuntime: FATAL EXCEPTION: Thread-19
java.lang.StackOverflowError: stack size 1040KB
at java.lang.String.getChars(String.java:787)
at com.android.internal.util.FastXmlSerializer.append(FastXmlSerializer.java:115)
at com.android.internal.util.FastXmlSerializer.append(FastXmlSerializer.java:139)
at com.android.internal.util.FastXmlSerializer.escapeAndAppendString(FastXmlSerializer.java:163)
at com.android.internal.util.FastXmlSerializer.text(FastXmlSerializer.java:413)
at com.android.internal.util.XmlUtils.writeValueXml(XmlUtils.java:662)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:307)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:276)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:242)
at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:199)
at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:778)
at android.app.SharedPreferencesImpl.access$900(SharedPreferencesImpl.java:55)
at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:647)
at android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:666)
at android.app.SharedPreferencesImpl.access$100(SharedPreferencesImpl.java:55)
at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:585)

StackOverflowError because of too deep view-hierarchy in Android

we get in the Play Store some crash reports of this kind:
java.lang.StackOverflowError
at android.graphics.Paint.getTextRunAdvances(Paint.java:1753)
at android.graphics.Paint.getTextRunAdvances(Paint.java:1726)
at android.text.TextLine.handleText(TextLine.java:758)
at android.text.TextLine.handleRun(TextLine.java:981)
at android.text.TextLine.measureRun(TextLine.java:425)
at android.text.TextLine.measure(TextLine.java:299)
at android.text.TextLine.metrics(TextLine.java:273)
.
.
.
.
at android.view.View.draw(View.java:11069)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2203)
at android.view.View.getDisplayList(View.java:10505)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:876)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:1916)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1640)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2454)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4477)
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:788)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
We had such an exception on one of our test devices and it came out, that it was because of the maximum depth of the view hierarchy.
I know that the recommendation for the max depth is <10.
However, this value is quite ambitious if you have a reasonably complex app.
We use AppCompat v21 and a ViewPager on the Main-Acitivity with Fragments.
For this reason i think we have alot of "meaningless" views, which simply encapsulates one child.
Or What is the purpose of the following layouts:
-NoSaveStateFrameLayout
-NativeActionModeAwareLayout
-FitWindowsFrameLayout
Overall, we arrive a total depth of 23 including the PhoneWindowDecorView.
Our Viewtree looks like this:
Picture from Hierarchy View
The first Views from the RootView:
Picture from Hierarchy View
Nevertheless, our app works even on very old and poor Android 2.3 devices.
Why does the problem still occur in the real world.

Android: Can I ignore the errors " Parent view is not a TextView " and " sendUserActionEvent() mView == null "?

In my Android app, I am constantly getting the following two errors in my logcat:
06-02 20:33:16.070: E/MoreInfoHPW_ViewGroup(13983): Parent view is not a TextView
06-02 20:33:12.010: E/ViewRootImpl(13983): sendUserActionEvent() mView == null
My app runs completely fine in spite of these two errors, and I've found no definitive answer as to whether or not they are harmful (or even fixable!) errors or if they can be safely ignored. Thus far I've been doing fine just ignoring them, but I wanted this to be asked since I'm sure I am not the only one confused as to what these two errors mean.
For reference, I am getting these errors while running the app via adb on a Samsung Galaxy S5.
EDIT: The Parent view is not a TextView error happens at many times, but notably it happens whenever I press the back button on the action bar and when I start a new activity by pressing a button. I'm using the support library, minSdk=8.
Yes you can ignore, it's a known issue with Samsung models. If it bothers you, maybe you can replace
context.startActivity(....);
with:
startActivity(new Intent(....));
and see if it works for you too, as indicated in this answer:
https://stackoverflow.com/a/24592235/3202370
I hope it helps.

Using ShowcaseView with the v7 appcompat ActionBar

I'm using the ShowcaseView android library to add a welcome screen when my app is first launched.
Now, on 4.0+ (and possibly 3.0, however I haven't got a device to test it) it works perfectly, however on Gingerbread, the app crashes with the following error.
09-10 15:30:31.182 1650-1650/net.rymate.notes E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: insertShowcaseViewWithType cannot be used when the theme has no ActionBar
at com.github.espiandev.showcaseview.ShowcaseView$2.run(ShowcaseView.java:231)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Is there any way to make this work on gingerbread? I want my app to be able to work on nearly all devices, which is why I'm using a lot of support APIs.
Any help is appreciated!
The short answer is "not yet". Actually working on it as I type! Check the Github issue here for more information.
Fixed in this pull request
Feel free to fork it
You can use a custom view like this: Set Custom Font in the Action Bar,
then create new ShowcaseView like:
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.hideOnClickOutside = true;
ShowcaseView sv = ShowcaseView.insertShowcaseView(v, this,
"TITLE", "subtitle", co);

What's causing this NullpointerException?

I've received a crash report with the following log content:
java.lang.NullPointerException
at android.webkit.PluginFullScreenHolder.show(PluginFullScreenHolder.java:85)
at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:8553)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
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)
I have tried searching for PluginFullScreenHolder across the web, but line 85 appears to be a comment in the classes I've found.
I'm guessing the crash is related to a WebView - possibly because I'm trying to load null, but I'm very unsure of this, especially because I don't see a way for the URL to be null.
I believe the report comes from a Galaxy Nexus (on Android 4.0), if that makes any difference, but I'm not sure. If not, it's a Honeycomb device.
Anyone with experience in PluginFullScreenHolder?
Here's my code
web = (WebView) findViewById(R.id.webView1);
web.setBackgroundColor(android.R.color.black);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setPluginsEnabled(true);
web.getSettings().setUserAgent(1);
web.getSettings().setSupportZoom(false);
web.loadUrl("http://www.justin.tv/widgets/live_embed_player.swf?auto_play=true&fullscreen=true&start_volume=100&hostname=www.justin.tv&channel=" + this.getIntent().getExtras().getString("channelName"));
The weird thing is that the crash report from Market doesn't mention anything about my code - nothing what so ever - you're looking at the complete log above. It's PluginFullScreenHolder.java, no doubt.
Edit 2:
Found the correct class: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/webkit/PluginFullScreenHolder.java#PluginFullScreenHolder.show%28%29
The line in question is:
client.onShowCustomView(mLayout, mOrientation, mCallback);
Here is the PluginFullScreenHolder.java source code for android 4.0.
At line 84, you have mWebView.getWebChromeClient() which returns null according to your exception (it is used at line 85 without null check).
A workaround is to set an empty WebChromeClient (which is called when something that might impact a browser UI happens, for instance, progress updates and JavaScript alerts are sent here) :
web.setWebChromeClient(new WebChromeClient());
But this is really strange because it should never be null.
I don't know if it can bu useful and not sure about it, but it seems like the exception is related to the superclass:
android.app.Dialog
in the method show().
You might want to take a look to the source code.
Have you tried to initialize "web"?
WebView web = new WebView(this);
web = (WebView) findViewById(R.id.webView1);
if you declared your variable like this
private WebView web;
You will get the NullpointerExeption, you must initialize the object.

Categories

Resources