Wednesday, November 12, 2014

Netbeans & Android - Step by Step Tutorial

Recently, I have been given an assignment to develop android application. Since, It was my first time to actually have a taste of it so I googled alot! But in all seriousness, I couldn't get hands on Netbeans and Android tutorial for beginners. So, I am going to help you with whatever I learned these past few days. I will write down steps for now. Pictorial tutorial will be uploaded later.

1) Download & Install Android SDK (Stand-alone version)

Remember, the android SDK only installs the basic tools and nothing for development. You can't even run an emulator after installing SDK. For development and emulator, follow further steps.
 
2) Run SDK Manager. You will come across various APIs and Tools by Android. Download what's your need. Here are the basic options that you can use to start developing.

SDK Manager

3) If you have Netbeans installed. Then go to next step. Else download & install from HERE

4) Start Netbeans. You will be needing NBAndroid package to start android development in Netbeans. There are two steps (online and offline) to get NBAndroid on your machine.
OR

5) Once done, you will now set ANDROID SDK location in Netbeans. Follow this..
  •             Tools -> Options -> Miscellaneous -> Android -> Enter SDK Location -> OK
6) You are now ready for Android Development. Follow these for your new android Project
  •  File -> New Project -> You will find ANDROID in categories -> Select Android Project -> Write Project Name -> Write package name e.g. com.android.test.app -> Write Activity Name (Its your MAIN) -> Select Target -> OK
DONE!!! 

Feel free to comment. I will write about first project in next post.

Saturday, February 22, 2014

[Solved] Signer Cetificate Warning

If you find out warnings related to Signer Certificate that will expire in 6 months and you get worried. Worry not!! Here is what you should do to dust it off!


Right-click project and go to Properties


Uncheck 'Request Unrestricted Access' and Press OK!


[Solved] Error: Controller is not defined on root component

If you happen to come across this error in you FXML file and you find out that you did mentioned fx:controller tag in your FXML file and its RED underline, then it means that your Netbeans needs update.

When you install Netbeans initally, it will show you some updates after connecting to internet. If you somehow ignore them or failed to update then these errors will show up. Remember that these errors will only show up when you save the project using Scene Builder. Scene Builder has latest update of JavaFx package than Netbeans. Upon updation, both will have same versions.

Here is the code that you will find in FXML file using Netbeans IDE :

...xmlns:fx="http://javafx.com/fxml" fx:controller="netbeansjavafxtest.FXMLDocumentController">

whereas after saving the file using Scene Builder, the above line will change to :

...xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"

fx:controller="netbeansjavafxtest.FXMLDocumentController">

After updating the Netbeans, there will be no more Red Underlines on the above code. Updating Netbeans is quite simple.Easy Peasy!

JavaFx Beginners Tutorial - Scene Builder + Netbeans

When I was tasked to start work on JavaFx using Scene Builder & Netbeans, I shivered. Because, both were unknown to me then. Google helped but I have come to a point that most of the tutorials were not meant for beginners (they were labelled but they were not in true sense). So, I decided to make a pictorial post of it. Here I start...

Pre-requisites: JRE , Netbeans & Scene Builder installed.

1. Start Netbeans and Open New Project


2. Select JavaFx FXML application , Enter project name (we are using NetbeansJavaFxTest here) and location details & Project is made.





3. Check FXML(Flexible XML) file which is created automatically by Netbeans. If you have Scene Builder installed, double-clicking the FXML file will open Scene Builder but right-clicking and clicking EDIT will open FXML page in Netbeans.


If you double-click the file but Scene Builder doesn't open up, check the integration in Net beans by going into Tools -> Options






4. Run Program by clicking Build and then PLAY button. Output window will appear of the above created project.

Clicking on Button 'Click Me!' will result in showing Text 'Hello World' on screen and 'You Clicked Me!' on output screen in Netbeans IDE.


5. Now, its time to start Scene Builder and add some buttons of our own. Here is how Scene Builder Looks like (Remember we went there by double-clicking the FXML file)

6. Add Button and Label from Controls section by Drag and Drop. When you add them to the project, check that they also get listed in Hierarchy pane. Correspondingly, each control has properties which you can change. We will label the button etc as desired.







7. Now give Name & Event association to the control by going into Code section of Properties pane. Here we write 'onbtnPress' event as desired by us. (You can associate already created events but that will be explained later)






8. Check that Yellow warnings appear at the top. Here they mean that the identities and events given to controls are not part of controller (main Class having the events code)




9. Just to check what changes you can expect in Controller class after doing these changes in Scene Builder, you can click on Sample Skeleton and see the @FXML labels, events and methods. Remember, that its just a sample and not the exact code written in background right now.



10. Click Save and FXML file is saved. Go to Netbeans and check the FXML file (Edit) and you will find new tags and events added to it. But since they are not mentioned in Controller class so, they will give Error.






11. Here is the magic trick. Right-click FXML file and click on Make Controller. It will add up all the events etc that you made in Scene Builder earlier. If you check the FXML file, it will be having no more Errors after you do the above steps and build it.




12. Now, add the code to the events that you have created (onbtnPress in our case). We will just add Text to the label which was earlier created. Build the program Run it & you will get the output as desired.







That's all for the beginners. Now you know how to make changes to scene builder which gets reflected in Netbeans and how you add them back. For any queries, keep commenting!