gpt4 book ai didi

android - 调用addView()时MergeAdapterDemo崩溃

转载 作者:行者123 更新时间:2023-12-03 16:55:52 25 4
gpt4 key购买 nike

我正在尝试运行commonsguy的MergeAdapterDemo。当我注释掉对addView的调用时,代码将编译并运行良好。例如,运行良好:

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

adapter=new MergeAdapter();
arrayAdapter=buildFirstList();
adapter.addAdapter(arrayAdapter);
//adapter.addView(buildButton(), true);
adapter.addAdapter(buildSecondList());
//adapter.addView(buildLabel());
adapter.addAdapter(buildSecondList());

但是,这将崩溃:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

adapter=new MergeAdapter();
arrayAdapter=buildFirstList();
adapter.addAdapter(arrayAdapter);
adapter.addView(buildButton(), true);
adapter.addAdapter(buildSecondList());
adapter.addView(buildLabel());
adapter.addAdapter(buildSecondList());

这是当崩溃发生时的调用堆栈:
Thread [<1> main] (Suspended (exception NoClassDefFoundError))  
MergeAdapter.addViews(List, boolean) line: 101
MergeAdapter.addView(View, boolean) line: 78
MergeAdapter.addView(View) line: 64
MergeAdapterDemo.onCreate(Bundle) line: 52
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1611
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1663
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117
ActivityThread$H.handleMessage(Message) line: 931
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 3683
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597
NativeStart.main(String[]) line: not available [native method]

我正在使用位于他页面下载部分的预建.jar文件。

关于如何使它工作的任何建议?谢谢!

最佳答案

101行是

 addAdapter(new SackOfViewsAdapter(views));

但是您没有 SackOfViewsAdapter类。

https://github.com/commonsguy/cwac-merge/blob/master/README.markdown说:

This project requires the CWAC SackOfViewsAdapter. A copy of a compatible JAR can be found in the libs/ directory of the project, though you are welcome to try newer ones, or ones that you have patched yourself.



因此,您还需要在项目中包括该库。

关于android - 调用addView()时MergeAdapterDemo崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9075431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com