Wrox Programmer Forums
| 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 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
  #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
Code:
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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

}
And here's main.xml:

-----------
{code]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLinLayout"
android:orientation="vertical">

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

</LinearLayout>
[/code]
  #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
Default

You didn't mention anything about your manifest file. You should post that also.
  #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:

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

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

<resources>
  <string name="app_name">MyView</string>
  <string name="main_title">MyView Dev</string>
</resources>
  #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
Default

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:

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">

<com.jw.MyView.MyView 
    android:id="@+id/myView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />

</LinearLayout>
Jeff S.
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
Default

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!

Jim


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





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