为什么我不能通过dev c编译简单项目

时间:2018-07-28 11:47:42

标签: c

我不知道为什么开发人员无法编译下面的简单项目。

  

错误:Project1.exe已停止工作。

public class ActionButtonsAdapter extends RecyclerView.Adapter<ActionButtonsAdapter.ViewHolder>{

private List<Button> dataButtons;

static class ViewHolder extends RecyclerView.ViewHolder {

    Button actionButton;


    ViewHolder(View v) {
        super(v);

        actionButton = v.findViewById(R.id.action_button_rv);

    }

}

public ActionButtonsAdapter(List<Button> dataButtons){

    this.dataButtons = dataButtons;

}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {

    holder.actionButton = dataButtons.get(position);
    //i think the problem is here, maybe
}

@Override
public ActionButtonsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){

    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_actionbutton_layout, parent, false);
    return new ViewHolder(v);

}

@Override
public int getItemCount() {
    return dataButtons.size();
}

2 个答案:

答案 0 :(得分:1)

对于一个,您的项目确实可以编译,因为您遇到运行时错误。

发生运行时错误,因为您没有正确使用scanf。格式字符串后面的scanf参数应为变量的指针。

我不知道您使用的是哪个编译器,但是任何相当现代的编译器都会向您提供有关此的警告,例如这是Clang的输出:

apa.c:9:20: warning: format specifies type 'int *' but the argument has type 'int' [-Wformat]
        scanf("%d",n);
               ~~  ^

将其更改为scanf("%d",&n);可使程序正常工作。

https://linux.die.net/man/3/scanf

答案 1 :(得分:0)

首先,您得到的错误不是编译错误,而是运行时错误。 其次,当运行到达scanf行时发生。此函数需要可变地址来输入值。

替换此:

scanf("%d", n);

与此:

scanf("%d", &n);