As the javadoc for CtNewMethod
states
The source code must include not only the method body but the whole declaration
It must therefore contain the {}
, like
String str = "public static void main(String[] args){}";
However, two more things will give you problems.
First, you don't have a default (or a no arg) constructor. Add one
ct.addConstructor(CtNewConstructor.defaultConstructor(ct));
Second, the CtMethod#setBody(..)
method completely replaces the method body. So you can't do what you are doing. If you want all of those calls, you'll need to put them together
n.setBody("{HelloClass a = new HelloClass();a.sayHello();}");