Hi all:
I am writing a adapter for a specific app, the problem I met is:
I have only 1 listview in main.xml, and the row style is defined in
file_row.xml. If I simply use
list.setAdapter(new ArrayAdapter<String>(this, R.layout.file_row,
R.id.file_name, items));
where items is a ArrayList<String>, everything works well.
But if I use my custom Adapter, say,
list.setAdapter(new MyOwnListAdapter(this, filename));
and in the class of MyOwnListAdapter, the code has been simplified as
class MyOwnListAdapter extends ArrayAdapter<String> {
// Constructor
public IconifiedTextListAdapter(Activity context,
ArrayList<String>
filename_list) {
super(context, R.layout.file_row, R.id.file_name,
filename_list);
}
public View getView(int position, View convertView, ViewGroup
parent) {
return parent;
}
}
But I always met the problem which is:
E/AndroidRuntime(30321): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(30321): java.lang.ClassCastException:
android.widget.LinearLayout$LayoutParams
E/AndroidRuntime(30321): at
android.widget.ListView.measureScrapChild(ListView.java:1068)
E/AndroidRuntime(30321): at
android.widget.ListView.measureHeightOfChildren(ListView.java:1149)
E/AndroidRuntime(30321): at
android.widget.ListView.onMeasure(ListView.java:1060)
E/AndroidRuntime(30321): at android.view.View.measure(View.java:7966)
E/AndroidRuntime(30321): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3077)
E/AndroidRuntime(30321): at
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:
888)
E/AndroidRuntime(30321): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
E/AndroidRuntime(30321): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
E/AndroidRuntime(30321): at android.view.View.measure(View.java:7966)
E/AndroidRuntime(30321): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3077)
E/AndroidRuntime(30321): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime(30321): at android.view.View.measure(View.java:7966)
E/AndroidRuntime(30321): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
E/AndroidRuntime(30321): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
E/AndroidRuntime(30321): at android.view.View.measure(View.java:7966)
E/AndroidRuntime(30321): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3077)
E/AndroidRuntime(30321): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
E/AndroidRuntime(30321): at android.view.View.measure(View.java:7966)
E/AndroidRuntime(30321): at
android.view.ViewRoot.performTraversals(ViewRoot.java:767)
E/AndroidRuntime(30321): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1639)
E/AndroidRuntime(30321): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(30321): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(30321): at
android.app.ActivityThread.main(ActivityThread.java:4568)
E/AndroidRuntime(30321): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(30321): at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(30321): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(30321): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(30321): at dalvik.system.NativeStart.main(Native
Method)
I/Process ( 95): Sending signal. PID: 30321 SIG: 3
I/dalvikvm(30321): threadid=7: reacting to signal 3
E/dalvikvm(30321): Unable to open stack trace file '/data/anr/
traces.txt': Permission denied
D/VoiceDialerReceiver(30306): onReceive Intent
{ act=android.intent.action.PACKAGE_REMOVED
dat=package:info.likun.gshare flg=0x20000000
cmp=com.android.voicedialer/.VoiceDialerReceiver (has extras) }
D/HtcWidgetScanner(29205): action -
android.intent.action.PACKAGE_REMOVED
D/HtcWidgetScanner(29205): packageUid - 10064
D/VoiceDialerReceiver(30306): onReceive Intent
{ act=android.intent.action.PACKAGE_ADDED
dat=package:info.likun.gshare flg=0x20000000
cmp=com.android.voicedialer/.VoiceDialerReceiver (has extras) }
W/BackupManagerService( 95): dataChanged but no participant
pkg='com.htc.launcher' uid=9999
D/PackageInstallationReceiver(15805): Removing.../data/local/tmp/
info.likun.gshare.apk
E/PackageInstallationReceiver(15805): Remove /data/local/tmp/
info.likun.gshare.apk Fail!
W/System.err(15805): java.io.IOException: Error running exec().
Commands: [/system/xbin/su, 0, /system/bin/rm, /data/local/tmp/
info.likun.gshare.apk] Working Directory: null Environment: null
W/System.err(15805): at
java.lang.ProcessManager.exec(ProcessManager.java:196)
W/System.err(15805): at java.lang.Runtime.exec(Runtime.java:225)
W/System.err(15805): at java.lang.Runtime.exec(Runtime.java:313)
W/System.err(15805): at java.lang.Runtime.exec(Runtime.java:246)
W/System.err(15805): at
com.htc.android.psclient.PackageInstallationReceiver.removeTempPackageFile(PackageInstallationReceiver.java:
30)
W/System.err(15805): at
com.htc.android.psclient.PackageInstallationReceiver.onReceive(PackageInstallationReceiver.java:
22)
W/System.err(15805): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2736)
W/System.err(15805): at android.app.ActivityThread.access
$3100(ActivityThread.java:126)
W/System.err(15805): at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1970)
W/System.err(15805): at
android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(15805): at android.os.Looper.loop(Looper.java:123)
W/System.err(15805): at
android.app.ActivityThread.main(ActivityThread.java:4568)
W/System.err(15805): at java.lang.reflect.Method.invokeNative(Native
Method)
W/System.err(15805): at java.lang.reflect.Method.invoke(Method.java:
521)
W/System.err(15805): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
D/dalvikvm( 227): GC freed 2373 objects / 139472 bytes in 3446ms
W/System.err(15805): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
W/System.err(15805): at dalvik.system.NativeStart.main(Native Method)
W/System.err(15805): Caused by: java.io.IOException: No such file or
directory
W/System.err(15805): at java.lang.ProcessManager.exec(Native Method)
W/System.err(15805): at
java.lang.ProcessManager.exec(ProcessManager.java:194)
W/System.err(15805): ... 16 more
I thought the self-defined Adapter class actually has only one line of
valid execution, which is
super(context, R.layout.file_row, R.id.file_name, filename_list);
It's essentially identical to direct calling of
list.setAdapter(new ArrayAdapter<String>(this, R.layout.file_row,
R.id.file_name, items));
Then why I always got this error if I call my own Adapter?
Any hint or suggestion would be very appreciated.
--
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