Find your way around MySQL console (command line)

Using graphic tools to interact with database is very easy but in many cases you might find yourself in a situation that you don’t have way other than a simple CLI for example because you are connecting to the server via SSH. That’s why it is useful to know the basic commands to at least find your way around and get the job done.
Continue reading Find your way around MySQL console (command line)

Fixing BadTokenException in Android WebView

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

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl(url);

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

Java: Multiple class declarations in one file

If you already know why the following code fail to compile, then you don’t need to continue reading!
// File: MyClass.java
public class MyClass {
// field, constructor, and
// method declarations
}
public class MyClass2 {
// field, constructor, and
// method declarations
}

However, if you are surprised then continue reading:
Continue reading Java: Multiple class declarations in one file