[CREATE] Hello World program for android via Netbeans

Well friends, as I started programming on android on my windows with IDE as Netbeans. I am writing every step that were problems to me and how I solved then. You can get subscribed so that you can get more and more help regarding android application development. Before going to all the thing you must have first setup all the requirements as of my previous article.
Now, just follow the step as I tell below for the very first android program on as HelloWorld.
Goto File > New Project.
Choose a project a Android > Android Project. And click Next>.
There are some information to be filled up as below:

The click Finish.
You find the source code as:

package com.test.helloworld;
import android.app.Activity;
import android.os.Bundle;
public class helloworld extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Now what you do is change the code to following:

package com.test.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class helloworld extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text1 = new TextView(this);
text1.setText(“Hello World”);
setContentView(text1);
}
}

After that is done, Build the program.
After the program is build successfully, Run the program. An emulator window will open. After the emulator opens and the OS on the emulator gets loaded, go to its Menu. And view the program named helloworld. Your will see the result. If you could not find the application that you just made, you have to do the installation of the application manually.
Command-line installation of android .apk file

27 thoughts on “[CREATE] Hello World program for android via Netbeans”

  1. I do have an issue. I have been learning the ins, and outs of java, and have made the move from C++, C# to java. I’m comfortable with the language, and your tutorial was brilliant. Got me through the set up with no hitches at all, however, I do have an issue with the code.
    For this tutorial, I have followed you to the “T”, but my compiler (Netbeans 6.9, using Android 2.1 update, as you are) is failing to compile. It’s saying that it can’t find main in setContentView(R.layout.main);
    Now, I did have the problem with R in the same statement, however upon importing android.R it was corrected. I have tried importing android.R.layout to fix it, but I still get the  same error.
    Know anything about it?

    1. Hey, yes it Initially says some error at setContentView(R.layout.main). But after a compilation, it gets well corrected by automatically adding a “Generated Source Package” named “R.java” where you can find the properties that you need like R.layout.main.
      Yes I too got a simple error on my program, but when I created a new project the problem is resolved.
      Have fun.

      1. Hey, I am getting an error . … I built , run and the emulator starts perfectly … Then I get the error message box :
        Sorry !
        The application MainActivity(process com.test) has stopped unexpectedly. Please try again.
        Followed by a Force Close button.
        This happens everytime i click on the MainActivity from the  menu inside the emulated device.

        1. Ah, the problem is most probably with AndroidManifest.xml, such problem comes from that.
          As you know in JAVA, the fileName must be equal to the executing ClassName so I guess that might be the problem in your case

          1. I retyped the output line and it worked and then deleted the pasted line. Problem solved.

    2. Here you go with the code:
      /* AUTO-GENERATED FILE. DO NOT MODIFY.
      *
      * This class was automatically generated by the
      * aapt tool from the resource data it found. It
      * should not be modified by hand.
      */
      package com.app.myapp;
      public final class R {
      public static final class attr {
      }
      public static final class drawable {
      public static final int icon=0x7f020000;
      }
      public static final class layout {
      public static final int main=0x7f030000;
      }
      public static final class string {
      public static final int app_name=0x7f040000;
      }
      }

  2. I get a “multiple annotations here [2] – click to cycle” problem in the 2nd line here:
       TextView text1 = new TextView(this);
        text1.setText(“Hello World”);
        setContentView(text1);
    And it says that there’s no fixable error. What could it be?

      1. It was all in place. That’s what I was copying:
            package com.test.helloworld;
           
        import android.app.Activity;
        import android.os.Bundle;
        import android.widget.TextView;
            public class helloworld extends Activity
            {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            TextView text1 = new TextView(this);
            text1.setText(“Hello World”);
            setContentView(text1);
            }
            }
        So, any recommendations on how to fix the error or start the emulator generally?

        1. Oops, I guess my bad(or wordpress), have you tried changing all the ” -> (quote one from keyboard).
          Try that one out.
          And problem with starting emulator, just open the AVD(Android Virtual Device) Manager and Create a new Device, and press start 🙂 Starting takes your all the time 🙁

          1. text1.setText(‘ Hello World ‘);
            Still the same.
            I press ‘ and I get a ‘ ‘ so as to quote my code inside it and I write Hello World, but I keep getting a “Unclosed Character Literal” problem.

          2. Eclipse is far too heavy for my laptop at the time being. Anyways, I have attached a screenshot with the problem, so that you can see where the error is and give me your suggestion. Thanks

          3.  Usually a single quote ‘, is used for single Characters in Java. So, I would suggest you using double quote(not the single quote twice, its on your keyboard).
            (“Hello World”);

          4. Great! Thank you! I debugged the code, but still, I have sth to go and that’s the message I get when I’m trying to launch and ADV device as well.
            PANIC: Could not open AVD config file: C:UsersΓιολάντα.androidavdHelloWorld.avd/config.ini

          5. Have you hidden your username or “Γιολάντα” is the original one?
            The same problem with my friend. He had a name as “Capt’n Sparrow” and as ‘ makes the string unusable, In the same way, you username isn’t supporting.
            I would suggest you to create a new user with good name 🙂 like “opeth”

          6. I’ll try it. The name however, is in Greek, but, still, I don’t know if its a compatible language. Thanks.

  3. Hey there…. I am new to Android programming …. and I am getting an error saying package R does not exist… I am programming in NetBeans IDE 8.0 ….. please help….

Leave a Reply

Your email address will not be published. Required fields are marked *