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]