Question

I am developing an Android app using Phonegap and jQueryMobile, working in Eclipse. I want the app, with the user's permission, to auto-install a launcher icon on the user's "desktop". I've found the example LauncherShortcuts.java on Android Developers, and I am almost to the point of getting it to work. That's a big achievement, since I know extremely little of Java programming.

Almost.

This is the example code online: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html

One string or thingy in the code refuses to cooperate. Line 83...

TextView intentInfo = (TextView) findViewById(R.id.txt_shortcut_intent);

...has this constant or variable in it called "R.id.txt_shortcut_intent", and Eclipse says it doesn't recognize the id part. If I follow its suggestion of adding a class 'id' in R., it tells me there is no field txt_shortcut_intent in 'R.id'. That doesn't surprise me.

I've been able to fix a few similar errors involving R.something_or_other. But not this one. My R.java only contains the classes attr,drawable,layout, and string.

What is going on here and most importantly, what should I do to get this thing up and running? The launcher icon is all that stands between here and actually launching the app (how ironic).

Was it helpful?

Solution

An android app uses an xml to define the layout of all the elements you want to display. In this case, you're missing an element that displays text called TextView. You don't have the Textview 'txt_shortcut_intent' defined in the xml, probably.

Here's the xml you're looking for (just copy and paste it into your main.xml): http://developer.android.com/resources/samples/ApiDemos/res/layout/launcher_shortcuts.html

OTHER TIPS

If you find any errors in the project. Sometimes id of R.java entries will be shifted to string folder or R.java.

For this choose

  1. project → clean
  2. file → close all
  3. click on your project
  4. See the entries in id of R.java your ids will be in this folder

The ADT Plugin in Eclipse can only rebuild the R class if there are no (Java) errors. Therefore, fix all errors and check if your layout ressource has the correct id (txt_shortcut_intent). It's worth a try to clean the project and restart Eclipse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top