Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 27th, 2009, 09:45 PM
Registered User
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Ch. 4 MyView RuntimeException

I'm interested in extending the View class to make a new UI class, much like the Ch. 4 MyView. So I'm trying to get MyView.java to work. But I keep getting a RuntimeException with few clues as to a solution, so I'd appreciate any advice.

I took the code snippet for the Ch. 4 MyView and created a simple Activity wrapper. Then I created a main.xml that should instantiate one MyView.

Here's the error:
Exception occurred: java.lang.RuntimeException (uncaught)"thread=<3> main", android.app.ActivityThread.performLaunchActivity() , line=2,141 bci=620
The problem seems seems to occur early; the jdb traceback is not obvious:

[1] android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2,141)
[2] android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2,157)
[3] android.app.ActivityThread.access$1800 (ActivityThread.java:112)
[4] android.app.ActivityThread$H.handleMessage (ActivityThread.java:1,581)
[5] android.os.Handler.dispatchMessage (Handler.java:88)
[6] android.os.Looper.loop (Looper.java:123)
[7] android.app.ActivityThread.main (ActivityThread.java:3,739)
java.lang.reflect.Method.invokeNative (native method)
[9] java.lang.reflect.Method.invoke (Method.java:515)
[10] com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run (ZygoteInit.java:739)
[11] com.android.internal.os.ZygoteInit.main (ZygoteInit.java:497)
[12] dalvik.system.NativeStart.main (native method)

There are basically three files for this application: MyView.java from the book, my wrapper MyViewActivity.java, and the layout main.xml. Here are the latter two:

-------------------------------- MyViewActivity.java
package com.jw.MyView;

import java.util.*;
import java.text.*;
import java.lang.*;
import android.app.*;
import android.widget.*;
import android.os.Bundle;

public class MyViewActivity extends Activity {

    private	MyView myView;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

	myView = (MyView) findViewById(R.id.myView);

And here's main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

<MyView android:id="@+id/myView">

Reply With Quote
  #2 (permalink)  
Old July 27th, 2009, 11:09 PM
Authorized User
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts

You didn't mention anything about your manifest file. You should post that also.
Reply With Quote
  #3 (permalink)  
Old July 28th, 2009, 12:18 AM
Registered User
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default AndroidManifest.xml

I did forget the manifest file but here it is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MyViewActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
    <uses-sdk android:minSdkVersion="2" />
And here's strings.xml too:

<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: strings.xml,v 1.7 2009/07/27 00:24:24 jim Exp $ -->

  <string name="app_name">MyView</string>
  <string name="main_title">MyView Dev</string>
Reply With Quote
  #4 (permalink)  
Old July 28th, 2009, 11:14 AM
Authorized User
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts

Ok, Jim. I think that your problem is inside your main.xml file. The MyView element isn't composed using the correct formats.

1) Since you created a custom View, I think you need to use the extended name of com.jw.MyView.MyView inside the XML.
2) Also, you need to add layout_width and layout_height rules. So the main.xml file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


Jeff S.
Reply With Quote
The Following User Says Thank You to sierawsk For This Useful Post:
jimw (July 28th, 2009)
  #5 (permalink)  
Old July 28th, 2009, 12:37 PM
Registered User
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts

Jeff, I am quite impressed that you were able to debug this code hands-off, and fingered both of my errors. I don't know how long it would have taken me to discover the fixes myself, but I know it would have been quite a while.

Hats off to you, and many thanks!

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Ch 2 - Ex 2 jkiernander BOOK: Ivor Horton's Beginning Visual C++ 2005 0 December 29th, 2007 08:47 PM
java.lang.RuntimeException: System properties file mshah101 Apache Tomcat 1 November 22nd, 2007 12:17 AM
ANOTHER Bug - Ch 7 Johnslg BOOK: Expert SQL Server 2005 Integration Services ISBN: 978-0-470-13411-5 1 August 30th, 2007 10:00 AM
Ch. 4 & Ch. 12 athena BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 23rd, 2004 10:54 AM
ch. 2 with C# Justin BOOK: Beginning ASP.NET 1.0 1 July 10th, 2003 03:59 PM

All times are GMT -4. The time now is 07:59 AM.

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