Well, a quick experiment shows that there might be a problem with a
LinearLayout as the view. Here's the code for getChildView. The
database stuff is tried and true. In my test case there are no level 3
items so just one TextView is created inside the LinearLayout.
@Override
public View getChildView(int appIndex , int tableIndex
, boolean
isLastChild, View convertView, ViewGroup parent) {
NameAndIdPair table = (NameAndIdPair) getChild(
appIndex ,
tableIndex );
SQLiteObjectListDbAdapter reportDb = null;
Cursor reports = null;
if( convertView == null ) {
convertView = new LinearLayout(
ThreeLevelListActivity.this );
}
else {
((LinearLayout)
convertView).removeAllViews();
}
try {
TextView tv;
reportDb =
new
SQLiteObjectListDbAdapter(ThreeLevelListActivity.this ,
prefs.getPrefString(IPCUtils.usernameKey) , table );
tv = new
TextView(ThreeLevelListActivity.this);
tv.setText(table.name);
((LinearLayout)
convertView).addView(tv);
reports = reportDb.getAllRecords(null);
for( int i = 0 ; i < reports.getCount()
; i++ ){
NameAndIdPair report = new
NameAndIdPair(
reports.getString(reports.getColumnIndex(SQLiteObjectListDbAdapter.dbColObjectName))
,
reports.getString(reports.getColumnIndex(SQLiteObjectListDbAdapter.dbColObjectId)));
tv = new
TextView(ThreeLevelListActivity.this);
tv.setText(report.name);
((LinearLayout)
convertView).addView(tv);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MissingPrefKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if( reportDb!= null ) {
reportDb.close();
}
if( reports != null ) {
reports.close();
}
}
return null;
}
This results in the following null pointer exception. I'm guessing
that I need to set up more parameters in the LinearLayout but I'm not
sure what. I should probably load it from a resource rather than
create it new on the spot. I'm not sure all the defaults are
appropriate for this experiment. Any comments?
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): FATAL EXCEPTION: main
10-13 17:49:13.642: ERROR/AndroidRuntime(16570):
java.lang.NullPointerException
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.AbsListView.obtainView(AbsListView.java:1317)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.ListView.makeAndAddView(ListView.java:1727)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.ListView.fillDown(ListView.java:652)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.ListView.fillSpecific(ListView.java:1284)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.ListView.layoutChildren(ListView.java:1558)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.AbsListView.onLayout(AbsListView.java:1147)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.View.layout(View.java:7035)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.View.layout(View.java:7035)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.View.layout(View.java:7035)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.View.layout(View.java:7035)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.View.layout(View.java:7035)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.os.Handler.dispatchMessage(Handler.java:99)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.os.Looper.loop(Looper.java:123)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
android.app.ActivityThread.main(ActivityThread.java:4627)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
java.lang.reflect.Method.invokeNative(Native Method)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
java.lang.reflect.Method.invoke(Method.java:521)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-13 17:49:13.642: ERROR/AndroidRuntime(16570): at
dalvik.system.NativeStart.main(Native Method)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en