How to Import Sample Programs for Java Programming
To learn Java programming, you can download sample programs to get you started. This import business can be tricky. As you move from one dialog box to the next, you see that many of the options have similar names. That’s because Eclipse offers many different ways to import many different kinds of items. Anyway, if you follow these instructions, you’ll be okay:
Download the sample code from the Java Programming for Android Developers for Dummies webpage.
On the Eclipse main menu, choose File→Import, as shown in the figure.
As a result, Eclipse displays the Import dialog box.
In the tree in the Import dialog box, expand the General branch.
In the General branch, double-click the Existing Projects into Workspace subbranch, as shown in the figure.
As a result, the Import Projects dialog box appears.
In the Import Projects dialog box, choose the Select Root Directory or the Select Archive File radio button, as shown in the figure.
The downloaded sample code lives in a folder named Java4Android_Programs or in an archive file named Java4Android_Programs.zip.
Click the Browse button to find the Java4Android_Programs.zip file or the Java4Android_Programs folder on the computer’s hard drive.
If you’re unsure where to find these items, look first in a folder named Downloads.
After you find Java4Android_Programs, the Import Projects dialog box in Eclipse displays the names of the projects inside the file. (Refer to the figure.)
Click the Select All button.
Click the Finish button.
As a result, the main Eclipse workbench reappears. The left side of the workbench displays the names of the sample Java projects, as shown in the figure.
After importing the code, you may see lots of red error markers indicating trouble with the projects. If you do, stay calm. The markers might disappear after several seconds. If they don’t, check the lower area of the Eclipse workspace for a message similar to Unable to resolve target ‘android-15’.
If you see such a message, it means that the code insists on an API level that you haven’t installed on your computer. To fix the problem, do the following:
On the Eclipse main menu, choose Window→Android SDK Manager.
As a result, the computer displays the Android SDK Manager. (No surprise here!)
Select the check box labeled Android 4.0.3 (API 15) or in whichever box is labeled with the missing API level number.
Click the Install button in the lower-right corner of the Android SDK Manager window.
Wait for installation to finish.
Close the Android SDK Manager.
When Eclipse restarts, you see the red error markers for a few seconds. But after a brief (and possibly tense) waiting period, the error markers go away. You’re ready to roll.