Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 8th, 2011, 01:29 PM
Registered User
 
Join Date: Feb 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Got some problems when I tried to code the ToDoList android app

Hi all!

First of all, Iam familiar with programming like C++, XML+++++, but I cant figure out this error I get in my XML-file, so far I am on step 6 where I should create the XML file that includes the new layout to the array.

Code:
<?xml version="1.0" encoding="utf-8"?>
<no.schedules.android.showSchedule
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_heigth="fill_parent"
android:padding="10dp"
android:scollbars="vertical"
andorid:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>
I've got this error: "error: Error parsing XML: unbound prefix", normally this is a error that appears when I misspelled something in the XML-file like anroid instead of android. But I guess the xml file cant find the packed or the class showSchedule. I have followed the tutorial correctly, but with some minor changes, like changing some class names, parameters to functions and I've given datatypes a different name.

This is what I've done so far:

Created two classes:

Schedules.java
Code:
package no.schedules.android;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;





public class Schedules extends Activity {
   

	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ListView list = (ListView)findViewById(R.id.liste);
        final EditText textEdit = (EditText)findViewById(R.id.edit);
        
        final ArrayList<String> schedule = new ArrayList<String>(); 	//oppretter array som viser timeplaner
        final ArrayAdapter<String> scheduleArray;
        scheduleArray = new ArrayAdapter<String>(this, R.layout.schedules_item, schedule);
        list.setAdapter(scheduleArray); 
        
        textEdit.setOnKeyListener(new OnKeyListener() { 
        	public boolean onKey(View v, int keyCode, KeyEvent event) {
        		
        		if(event.getAction() == KeyEvent.ACTION_DOWN)
        			if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN){
        				schedule.add(0, textEdit.getText().toString());
        				scheduleArray.notifyDataSetChanged(); 
        				textEdit.setText("");
        				return true; 
        			}        		
        		return false; 
        	}
        	
        	
        	
        });}}
showSchedule.java
Code:
package no.schedules.android;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;



public class showSchedule extends TextView  {
	private Paint marginPaint;
	private Paint linePaint;
	int paperColor;
	float margin;
	
	public showSchedule(Context context, AttributeSet ats, int a){ super(context, ats, a); init(); }

    public showSchedule(Context context) { super(context); init(); }
	
    public showSchedule(Context context, AttributeSet attrs) { super(context, attrs); init(); }
    
    private void init() {
    
    	Resources pickResource = getResources();
    	marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    	marginPaint.setColor(pickResource.getColor(R.color.notepad_margin)); 
    	linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    	linePaint.setColor(pickResource.getColor(R.color.notepad_lines));
    	paperColor = pickResource.getColor(R.color.notepad_paper);
    	margin = pickResource.getColor(R.color.notepad_margin); 
    
    }	
    	 @Override
    	 public void onDraw(Canvas canvas) {
    		 canvas.drawColor(paperColor); 
    		 
    		 canvas.drawLine(0, 0, getMeasuredHeight(), 0 , linePaint);
    		 canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth() , getMeasuredHeight(), linePaint);
    		 
    		 canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
    		 canvas.save();
    		 canvas.translate(margin, 0);
    		 super.onDraw(canvas); 
    		 canvas.restore();
    	 
    	 
    	 
    	 }
    }
Both files are located under the packed no.schedules.android in eclipse.

What am I doing wrong here? I appreciate all answers. Thanks!
Reply With Quote
  #2 (permalink)  
Old February 8th, 2011, 02:07 PM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2010
Posts: 12
Thanks: 0
Thanked 3 Times in 2 Posts
Default Looks a bit like a layout

Your XML looks a bit like a layout resource in that you have android:layout_width etc. But you are not saying what you are laying out, perhaps your XML should start with <LinearLayout or similar rather than <no.schedules.android.showSchedule

It may help to know exactly where you are in the book as well.

Hope that helps a little
Reply With Quote
  #3 (permalink)  
Old February 8th, 2011, 02:17 PM
Registered User
 
Join Date: Feb 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by aajshaw View Post
Your XML looks a bit like a layout resource in that you have android:layout_width etc. But you are not saying what you are laying out, perhaps your XML should start with <LinearLayout or similar rather than <no.schedules.android.showSchedule

It may help to know exactly where you are in the book as well.

Hope that helps a little
Thanks the code is on page 94-96. I've tried the following
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
no.schedules.android.showSchedule
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_heigth="fill_parent"
android:padding="10dp"
android:scollbars="vertical"
andorid:textColor="@color/notepad_text"
android:fadingEdge="vertical"
</LinearLayout>
But I only got more errors
Reply With Quote
  #4 (permalink)  
Old February 9th, 2011, 03:59 AM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2010
Posts: 12
Thanks: 0
Thanked 3 Times in 2 Posts
Default Misspelling of 'android'

Your original XML should have been OK, apart from the second to last android line where you have andorid:textColor="@color/notepad_text" rather than android:textColor="@color/notepad_text". The 'o' and 'r' in android are the wrong way around.

One easy way to spot this sort of thing if you have the entire project loaded is in the file that is giving you problems take out each line in turn until the problem goes away then you have identified the start of the problem and can work towards fixing it.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem/Question about the example code "ToDoList" thomas2004 BOOK: Professional Android 2 Application Development 0 February 3rd, 2011 05:38 AM
Chapter 11 code listing for Professonal Android 2 Application Development robertkji BOOK: Professional Android 2 Application Development 1 November 26th, 2010 08:45 AM
Code examples import without Android library baroquedub BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 July 26th, 2010 07:07 AM
Problems using <xsl:import in web app flanagaj XSLT 0 April 18th, 2006 08:40 AM
Problems running ThePhile web app kiekar BOOK: ASP.NET Website Programming Problem-Design-Solution 5 July 24th, 2003 07:39 PM



All times are GMT -4. The time now is 05:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.