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() {
    base.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:

1
2
3
4
5
6
7
8
9
10
11
12
13
#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.

Assign DNS name to virtual machine (here: Parallels Desktop 7)

Assigning a DNS name to a virtual machine can be a convenient thing. Do this is not very complicated, it requires some technical skill though. This tutorial shows how to do this with a Ubuntu 11.10 Linux server running under Parallels Desktop 7 on Mac OS X Lion. The basic principals described in this article work as well for any other combination, but that’s beyond this article (and that’s where your technical skill comes into play).

Read more →

Editing hidden and locked files on Mac OS X with TextWrangler

Sometimes one needs to edit a system configuration file on Mac OS X. While these files are usually text files, you can’t used Mac OS’ “TextEdit” tool to do this. Fortunately, there is a free alternative to “TextEdit” called TextWrangler.

Important: Make sure that you don’t use the AppStore version as this version doesn’t allow editing locked files. (Apple’s store guidelines prohibit this.)

First, select File –> Open... from the menu. Then, since system configuration files are often hidden or in hidden folders, select Show hidden items at the bottom of the “Open” dialog.

Open Dialog in TextWrangler

Then open the file you want to edit. You may notice that the file is in read-only mode (represented by the icon in the upper left corner).

TextWrangler in read-only mode

To switch to write mode, either click this icon or start editing the file’s content. In both cases you’ll be asked to unlock the file. After that, you can edit the file.

When you’re done, simply save the file. You’ll be asked for your password since you’re editing a system file (that doesn’t belong to you). And that’s it.

Note: The AppStore version doesn’t ask you for your password but instead asks you to save the file under a different name.