All posts by admin

Fixing BadTokenException in Android WebView

So you have successfully created a webView in your App and already loaded your URL into it.

However, any interaction with the page (such as a dropdown menu) will result in BadTokenException crash with the following error message;

FATAL EXCEPTION: main
android.view.WindowManager$BadTokenException: Unable to add window — token is not valid; is your activity running?

This happens when app wants to open a new dialog (e.g. for dropdown menu aka. spinner) while the container activity no longer exists.
Continue reading Fixing BadTokenException in Android WebView

Huge Outlook OST file

If you are thinking why Outlook OST file is growing bigger and bigger every day regardless of how many emails you delete.
It seems like no matter how much you try to keep your inbox clean the free space in your hard disk is not getting bigger but only smaller and smaller every day.
Thankfully there is solution to reduce the size of this monstrous file!
Outlook provides an option to compress the OST file and reduce its size. Here is how:
Continue reading Huge Outlook OST file

Getting warning when calling getView() in Fragment

if you are getting below warning from compiler in your class where you are trying to create Fragment instance;

Warning: Method invocation ‘getView().findViewById(R.id.test)’ may produce ‘java.lang.NullPointerException’

Then chances are you are inflating your layout in onCreateView and trying to access layout elements outside that method.
Continue reading Getting warning when calling getView() in Fragment

Android: setting width and height programatically

There are times when you need to change width and height of View elements you defined in your XML layout or you want to create elements dynamically.
In that case you need to grab the view element and changed its layoutParams. Like how it is done below:

LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.width = 200;
params.height = 200;
layout.setLayoutParams(params);

Continue reading Android: setting width and height programatically

Keeping leading zeros in Microsoft Excel

There are situations where you need leading zero in your data. For instance, product codes (SKU) or ZIP codes.
For example, when copy and pasting “0800” into Excel, it will be converted to “800”.
That’s because when you copy and paste this data into Microsoft Excel, by default Excel tries to parse the value according to that cells format. Therefore, Excel recognizes data as numeric and strip out the leading zero.
Continue reading Keeping leading zeros in Microsoft Excel