【问题标题】:App crashed with noClassDefFound error in ArrayAdpter Android应用程序在 ArrayAdapter Android 中因 noClassDefFounderror 而崩溃
【发布时间】:2015-04-17 13:18:16
【问题描述】:

我有一个自定义的listView,其中包含图像和文本视图。但是在getView 方法中,应用程序崩溃了。

我的代码:

@Override
    public View getView(final int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(layout, null);
    } 
    ImageView removeWatch = (ImageView) view.findViewById(R.id.remove_watch);
    removeWatch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d("BEFOERE","on click in menuwatchadapter");
        }
    });

数组适配器:

public class MenuListAdapter extends ArrayAdapter<MenuListModel> {

private Context context;
private int layout;
private List<MenuListModel> Model;

public interface ModelAction {
    public void removedModel(MenuListModel removedModel);
}

private ModelAction ModelActions;

public MenuListAdapter(Context context, int resource,
        List<MenuListModel> objects, ModelAction ModelActionListener) {
    super(context, resource, objects);
    this.context = context;
    this.layout = resource;
    this.Model = objects;
    this.ModelActions = ModelActionListener;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(layout, null);
    }

    ImageView remove = (ImageView) view.findViewById(R.id.remove);

    remove.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d("TEST","CLICKED");
        }
    });
    return view;
}

}

removeWatch.setOnClickListener 行,应用程序崩溃了。 谁能告诉我可能是什么问题?

注意:我使用的是 Android-Studio。

LOGCAT:

-13 15:01:25.502 28351-28351/com.example.watch E/AndroidRuntime:致命异常:主要 进程:com.example.watch,PID:28351 java.lang.NoClassDefFoundError: com.example.watch.adapter.MenuWatchListAdapter$1 在 com.example.watch.adapter.MenuWatchListAdapter.getView(MenuWatchListAdapter.java:95) 在 android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220) 在 android.widget.AbsListView.obtainView(AbsListView.java:2255) 在 android.widget.ListView.makeAndAddView(ListView.java:1790) 在 android.widget.ListView.fillSpecific(ListView.java:1337) 在 android.widget.ListView.layoutChildren(ListView.java:1620) 在 android.widget.AbsListView.onLayout(AbsListView.java:2087) 在 android.view.View.layout(View.java:14948) 在 android.view.ViewGroup.layout(ViewGroup.java:4631) 在 android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 在 android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 在 android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 在 android.view.View.layout(View.java:14948) 在 android.view.ViewGroup.layout(ViewGroup.java:4631)

【问题讨论】:

  • 附上你的 logcat 崩溃报告
  • @Manikandan:添加了 logcat
  • @Manikandan:添加了 ArrayAdapter
  • 不,我没有使用任何库。
  • 我不知道为什么,但我已经卸载了整个 android-studio 和 android sdk 并重新安装它,现在可以正常工作了。

标签: android-studio android-arrayadapter noclassdeffounderror


【解决方案1】:

把这行view = inflater.inflate(layout, null)改成

view = inflater.inflate(R.layout.Your_LAYOUT, null) 试试看。

【讨论】:

  • 布局是可变的,并且包含您建议的内容。但不工作。
  • 附加你的 ArrayAdapter 类
  • 你将布局变量声明为 int。我不确定你的布局是否正确。
  • 你在你的应用程序中使用任何库吗?
【解决方案2】:

我不知道为什么,但我已经卸载了整个 android-studio 和 android sdk 并重新安装它,现在可以正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多