 |
BOOK: Beginning Android Application Development
 | This is the forum to discuss the Wrox book Beginning Android Application Development by Wei-Meng Lee; ISBN: 978-1-1180-1711-1 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Android Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 2nd, 2012, 02:57 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
non-constant fields in case labels
.setIcon(R.drawable.icon) is flagged as unresolved error. I have already converted the "switch'" to If-else.
|
|

January 2nd, 2012, 08:01 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
|
|
Hi elunokid
The new version of the SDK changes the way some of the 'res' items are handled. So that R.ic_launcher is not a constant cannot be used in switch statements. There is a note about in the documentation. There is a quick-fix that will convert switch statements to ifs.
Sometimes icon does not work ( and sometime it does?) change the icon to ic_launcher.
It would help if you would tell us what code you are having the trouble in.
Hope this helps
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
|
|

January 4th, 2012, 10:03 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
non-constant fields in case lablesl
ON page 34 the following statements are being flagged as errors:
setContentView(R.layout.main)
setIcon(R.drawable.icon)
findViewbyid(R.id.btn..dialog)
I certainly would appreciate any help on this problem. I'm Bogged down.
Thank you
Elunokid
|
|

January 5th, 2012, 07:56 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
|
|
Hi Elunokid
Sounds like you have a problem in the folder 'gen'. This is where all the generated data is stored.
1 Click (+) on the 'gen' folder and then on the project name folder.
There should be a R.java folder, click (+) on that and the sub folders.
Are the items that you are having problems with there?
Under drawable there should be an 'ic_launcher' .
Under layout there should be 'main'
Under id there should be 'btn_dialog'
findViewbyid(R.id.btn..dialog) should be findViewbyid(R.id.btn_dialog)
also in main if.xml.
Change 'icon' to 'ic_launcher'
2 Are there any other errors shown?
If there are not any other errors and you are still having problems. Click on R.java and delete it. It should be regenerated and have the items described above.
If there are other errors, R. will not be generated until those have been resolved.
The 'id' in the switch is an int and not the same as R.id. the switch should work.
Hope this helps 
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
|
|

January 9th, 2012, 09:15 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
cannot be resolved
Hi Cliff
After following your directions on last forum that you sent me. Going into gen and verifying the stored data and deleting R.java . I am still getting the errors. "fields cannot be resolved". on the "R." fields.
Thank You for your patience.
Elunokid
|
|

January 11th, 2012, 07:50 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
|
|
Hi Elunokid
I'm not sure what you problem is. If the R. structure is there it should work. Please post the lines of code that have errors and the main.xml file and I will see if I can help you.
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
|
|

January 12th, 2012, 09:00 AM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
R. fields cannot be resolved
Hi Cliff
Here's the info that you requested on the last forum that you communicated.
main.xml and the lines of code with the errors.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btn_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to display a dialog" />
</LinearLayout>
-----------------------------------------------------------------------------------------------------------------------
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(1);
_progress = 0;
_progressDialog.setProgress(0);
_progressHandler.sendEmptyMessage(0);
// TODO Auto-generated method stub
}
});
_progressHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (_progress >= 100) {
_progressDialog.dismiss();
} else {
_progress++;
_progressDialog.incrementProgressBy(1);
_progressHandler.sendEmptyMessageDelayed(0, 100);
}
}
};
}
protected Dialog onCreateDialog(int id) {
if (id == 0) {
return new AlertDialog.Builder(this)
.setIcon(R.drawable.c_launcher)
.setTitle("This is a dialog with some simple text...")
.setPositiveButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"OK clicked!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? " checked!":
" unchecked!"),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
} else if (id == 1) {
_progressDialog = new ProgressDialog(this);
_progressDialog.setIcon(R.drawable.icon);
_progressDialog.setTitle("Downloading files...");
_progressDialog.setProgressStyle(ProgressDialog.ST YLE_HORIZONTAL);
_progressDialog.setButton(DialogInterface.BUTTON_P OSITIVE,"Hide", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Hide clicked", Toast.LENGTH_SHORT).show();
}
});
_progressDialog.setButton(DialogInterface.BUTTON_N EGATIVE, "Cancel", new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
});
return _progressDialog;
}
return null;
}
}
|
|

January 12th, 2012, 01:36 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
|
|
Hi Elunokid
OK new I have the code. What and where are the errors?
Cliff
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
|
|

January 12th, 2012, 07:57 PM
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
non-constant fields
Hi Cliff
Sorry about the misunderstanding. Here it goes again. the errors were copy and pasted from Eclipse. They are that the bottom.
Thank you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btn_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to display a dialog" />
</LinearLayout>
-----------------------------------------------------------------------------------------------------------------------
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(1);
_progress = 0;
_progressDialog.setProgress(0);
_progressHandler.sendEmptyMessage(0);
// TODO Auto-generated method stub
}
});
_progressHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (_progress >= 100) {
_progressDialog.dismiss();
} else {
_progress++;
_progressDialog.incrementProgressBy(1);
_progressHandler.sendEmptyMessageDelayed(0, 100);
}
}
};
}
protected Dialog onCreateDialog(int id) {
if (id == 0) {
return new AlertDialog.Builder(this)
.setIcon(R.drawable.c_launcher)
.setTitle("This is a dialog with some simple text...")
.setPositiveButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"OK clicked!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? " checked!":
" unchecked!"),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
} else if (id == 1) {
_progressDialog = new ProgressDialog(this);
_progressDialog.setIcon(R.drawable.icon);
_progressDialog.setTitle("Downloading files...");
_progressDialog.setProgressStyle(ProgressDialog.ST YLE_HORIZONTAL);
_progressDialog.setButton(DialogInterface.BUTTON_P OSITIVE,"Hide", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Hide clicked", Toast.LENGTH_SHORT).show();
}
});
_progressDialog.setButton(DialogInterface.BUTTON_N EGATIVE, "Cancel", new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
});
return _progressDialog;
}
return null;
}
}
********errors**********************
Description Resource Path Location Type
R.drawable.c_launcher cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 61 Java Problem
R.drawable.icon cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 96 Java Problem
R.id.btn_dialog cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 31 Java Problem
R.layout.main cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 29 Java Problem
|
|

January 12th, 2012, 08:27 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 86
Thanks: 3
Thanked 5 Times in 5 Posts
|
|
Hi Elunokid
Fix the two errors shown below.
When you go to put the values for R, type 'R.id.' and press CTRL-space.
This will give a list to select from.
The other two look good to me. Are you sure that the file R.java in in the 'gen' folder? If they are, then delete what you have for main and btn_dialog
and put them back with the CTRL-space trick.
Cliff
Quote:
Originally Posted by elunokid
Hi Cliff
Sorry about the misunderstanding. Here it goes again. the errors were copy and pasted from Eclipse. They are that the bottom.
Thank you
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btn_dialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to display a dialog" />
</LinearLayout>
-----------------------------------------------------------------------------------------------------------------------
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(1);
_progress = 0;
_progressDialog.setProgress(0);
_progressHandler.sendEmptyMessage(0);
// TODO Auto-generated method stub
}
});
_progressHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (_progress >= 100) {
_progressDialog.dismiss();
} else {
_progress++;
_progressDialog.incrementProgressBy(1);
_progressHandler.sendEmptyMessageDelayed(0, 100);
}
}
};
}
protected Dialog onCreateDialog(int id) {
if (id == 0) {
return new AlertDialog.Builder(this)
.setIcon(R.drawable.c_launcher) <<< lc_auncher
.setTitle("This is a dialog with some simple text...")
.setPositiveButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"OK clicked!", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
Toast.makeText(getBaseContext(),
items[which] + (isChecked ? " checked!":
" unchecked!"),
Toast.LENGTH_SHORT).show();
}
}
)
.create();
} else if (id == 1) {
_progressDialog = new ProgressDialog(this);
_progressDialog.setIcon(R.drawable.icon);
change the above lint to _progressDialog.setIcon(R.drawable.lc_launcher);
_progressDialog.setTitle("Downloading files...");
_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
_progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"Hide", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Hide clicked", Toast.LENGTH_SHORT).show();
}
});
_progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext(),
"Cancel clicked!", Toast.LENGTH_SHORT).show();
}
});
return _progressDialog;
}
return null;
}
}
********errors********************** [/
Description Resource Path Location Type
R.drawable.c_launcher cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 61 Java Problem
R.drawable.icon cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 96 Java Problem
R.id.btn_dialog cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 31 Java Problem
R.layout.main cannot be resolved MainActivity.java /Hello Project/src/net/elunokiddevelop/Dialog line 29 Java Problem
|
__________________
"Software to the Stars"
Failure is not an option. It comes bundled with your Microsoft products.
|
|
 |
|