Thursday, March 29, 2012

'findViewById()' error in Android development

Each time after adding a new widget into my Android project, the system always posts a null-point error. I am pretty sure the code should be fine as I just did Ctrl+C & Ctr+V. Some suggests to add 'this.' before calling this function. Something like:

Button myBtn = (Button) this.findViewById(R.id.myBtn);

However, it does not work for me. Eventually, I got a useful answer. It's better to clean the entire project before compiling the updated source code. Since I am using 'ant' for the compilation, it will be like this:

> ant clean
> ant debug
> adb -d install -r bin\xxx-debug.apk


No comments:

Post a Comment