Creating an Application class in Mono for Android

Android provides an Application class.

Base class for those who need to maintain global application state.

Here’s how to create such a class in Mono for Android:

[Application]  // <-- Attribute required
class MyApp : Application {
  // Required constructor
  public MyApp(IntPtr javaReference, JniHandleOwnership transfer) 
    : base(javaReference, transfer) { }

  // Test method - not required
  public override void OnCreate() {

Note: There can only be one such class in an Android application.

Meaningful C++ error message

During my time as a student at the University of Stuttgart we had to learn the programming language Ada. Back then I was swearing about the compiler error message because they were totally meaningless (at least to me).

I am currently working on a C++ project and I have to say that C++ isn’t an inch better than Ada. Consider the following code:

#include <Windows.h>
namespace Geometry {
  class Polyline { };
using Geometry::Polyline;
namespace OtherNS {
  Polyline* get() {
    return NULL;

Trying to compile this code gives you the following error message (on Visual C++ 2010):

using_test.cpp(10): error C2143: syntax error : missing ';' before '*'
using_test.cpp(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
using_test.cpp(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

What? Syntax error? And then you start looking where you missed a ;.

The problem, however, is completely different. It’s because there is a function called Polyline() defined somewhere in Windows.h and now the compiler tries to use this function as return type instead of the class Polyline (but doesn’t say anything about that). <irony>This, of course, becomes totally clear just by reading this extremely meaningful error message.</irony> *sigh*

GCC isn’t better here (in case you were blindly blaming Microsoft for writing bad error messages):

error: ‘Polyline’ does not name a type

By the way, the problem can be solved by placing the using statement inside the OtherNS namespace.

C vs. C++

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.

— Bjarne Stroustrup, developer of the C++ programming language

Eclipse Plugins

This is just a note to my self of what Eclipse plugins I’ll use. This list may, however, also be useful to you.

  • Subclipse: Subversion support
  • MercurialEclipse: Mercurial support
  • ExploreFS: This plugin allows you to open a file in Windows Explorer/Finder through the context menu.
  • CheckStyle: This plugins allows you define more precise rules for your code style. If a rule is violated, a warning is issued.
  • TestNG: Unit testing framework (much like JUnit)

To see what plugins have already been installed, go to Help –> Install new software… and click on What is already installed? at the bottom of the dialog.