I am using Eclipse and created HelloWorld and it works fine using emulator. Then I tried to create ToDoList app where you can enter text and click to submit, following the example on the book I have and getting an error that cause my app to force close when I interact with the application.
my directory structure: (please ignore other folders)
ProjectToDoList
|
|-----src
| |----com.test.dotolist
| |------ToDoList.java
| |------ToDoListItemView.java
------res
|
|----layout
|-------main.xml
|-------todolist_item.xml
I tracked where it is happening:
If I just use default layout in ToDoList.java like:
final ArrayList<String> todoItems = new ArrayList<String>();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_expandable_list_item_1, todoItems);
The app works fine. I can type in text and click a button for the text to show up.
But I'm trying to use my custom layout:
ToDoList.java,
final ArrayList<String> todoItems = new ArrayList<String>();
int resID = R.layout.todolist_item;
//create array adopter to bind the array to the listview
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, resID, todoItems);
//bind the array adapter to the listview
myListView.setAdapter(aa);
As you can see when I try to pass resID to ArrayAdapter, it compile and my app shows up on the emulator. But when I click submit button, it force to close.
todoList_item.xml
<?xml version="1.0" encoding="utf-8"?>
<com.test.todolist.ToDoListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>
The logcat output: (I can't figure out what's wrong)
W/KeyCharacterMap( 279): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
D/AndroidRuntime( 279): Shutting down VM
W/dalvikvm( 279): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 279): FATAL EXCEPTION: main
E/AndroidRuntime( 279): android.view.InflateException: Binary XML file line #2: Error inflating class com.test.todolist.ToDoListItemView
E/AndroidRuntime( 279): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
E/AndroidRuntime( 279): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
E/AndroidRuntime( 279): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 279): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
E/AndroidRuntime( 279): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
E/AndroidRuntime( 279): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
E/AndroidRuntime( 279): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
E/AndroidRuntime( 279): at android.widget.ListView.onMeasure(ListView.java:1109)
E/AndroidRuntime( 279): at android.view.View.measure(View.java:8171)
E/AndroidRuntime( 279): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime( 279): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
E/AndroidRuntime( 279): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
E/AndroidRuntime( 279): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
E/AndroidRuntime( 279): at android.view.View.measure(View.java:8171)
E/AndroidRuntime( 279): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime( 279): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime( 279): at android.view.View.measure(View.java:8171)
E/AndroidRuntime( 279): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
E/AndroidRuntime( 279): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
E/AndroidRuntime( 279): at android.view.View.measure(View.java:8171)
E/AndroidRuntime( 279): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
E/AndroidRuntime( 279): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime( 279): at android.view.View.measure(View.java:8171)
E/AndroidRuntime( 279): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
E/AndroidRuntime( 279): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
E/AndroidRuntime( 279): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 279): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 279): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 279): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 279): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 279): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 279): Caused by: java.lang.ClassNotFoundException: com.test.todolist.ToDoListItemView in loader dalvik.system.PathClassLoader[/data/app/com.test.dotolist-1.apk]
E/AndroidRuntime( 279): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 279): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 279): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 279): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
E/AndroidRuntime( 279): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
E/AndroidRuntime( 279): ... 32 more
W/ActivityManager( 66): Force finishing activity com.test.dotolist/.ToDoList
Please let me know if you need clarification.