应用程序在ArrayAdapter Android中与noClassDefFounderror崩溃

时间:2015-04-13 09:47:43

标签: android-studio android-arrayadapter noclassdeffounderror

我有一个包含图片和文字视图的自定义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");
        }
    });

ArrayAdpter:

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:FATAL EXCEPTION:main     处理: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)

2 个答案:

答案 0 :(得分:0)

将此行view = inflater.inflate(layout, null)更改为

view = inflater.inflate(R.layout.Your_LAYOUT, null)并尝试一下。

答案 1 :(得分:0)

我不知道为什么但是我已经整个android-studio和android sdk unistalled并重新安装它,现在它正在运行。