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:

  1. Download the sample code from the Java Programming for Android Developers for Dummies webpage.

  2. On the Eclipse main menu, choose File→Import, as shown in the figure.

    As a result, Eclipse displays the Import dialog box.

    image0.jpg
  3. In the tree in the Import dialog box, expand the General branch.

  4. 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.

    image1.jpg
  5. In the Import Projects dialog box, choose the Select Root Directory or the Select Archive File radio button, as shown in the figure.

    image2.jpg

    The downloaded sample code lives in a folder named Java4Android_Programs or in an archive file named Java4Android_Programs.zip.

  6. 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.)

  7. Click the Select All button.

  8. 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.

    image3.jpg

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:

  1. On the Eclipse main menu, choose Window→Android SDK Manager.

    As a result, the computer displays the Android SDK Manager. (No surprise here!)

  2. Select the check box labeled Android 4.0.3 (API 15) or in whichever box is labeled with the missing API level number.

  3. Click the Install button in the lower-right corner of the Android SDK Manager window.

  4. Wait for installation to finish.

  5. Close the Android SDK Manager.

  6. Restart Eclipse.

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.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.