p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 (http://p2p.wrox.com/forumdisplay.php?f=432)
-   -   Chapter 4 Compass (http://p2p.wrox.com/showthread.php?t=80093)

Cmdr July 11th, 2010 07:05 PM

Chapter 4 Compass
 
I am having trouble inflating my view from XML.

This is my main.xml file
Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <jason.android.compass.CompassView
            android:id="@+id/compassView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
        />
</LinearLayout>

And here i'm trying to use it...

Code:

package jason.android.compass;

import android.app.Activity;
import android.os.Bundle;

public class CompassExample extends Activity {
       
        //private CompassView compassView;
       
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.main);
        CompassView compassView = (CompassView)this.findViewById(R.id.compassView);
        //compassView.setBearing(50);
    }
}

It works as long as I don't access the compassView object (to set the bearing in this case). If I try to use the setBearing method, the application crashes.

And finally, if I don't load from a resource, it works just fine (example below).

Code:

package jason.android.compass;

import android.app.Activity;
import android.os.Bundle;

public class CompassExample extends Activity {
       
        //private CompassView compassView;
       
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        CompassView cv = new CompassView(this);
        setContentView(cv);
        cv.setBearing(50);
    }
}

I appreciate the help!


All times are GMT -4. The time now is 07:42 PM.

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