旧设备上的Android错误

时间:2017-05-23 14:23:59

标签: android onclick alertdialog nosuchmethoderror dialogfragment

我有一个Android应用程序,其中包含一个包含4个选项的对话框片段,每个选项都会显示一个警告对话框,其中包含有关点击的其他信息。

此功能适用于我的设备(Galaxy S7 Edge,Android 7.0),但我收到用户的报告,说他们的应用在点击选择时会崩溃(应该打开警报对话框)。

我的诊断程序说错误是由OnClick的NoSuchMethodError引起的,只发生在Android版本4.4,5.0,5.1(截至目前)。

有谁知道可能导致此问题的原因是什么?由于它可以在我的设备上运行,因此很难排除故障。

注意:如果更改了任何内容,我将使用View.OnClickListener。

错误堆栈跟踪示例:

java.lang.NoSuchMethodError: 
  at com.myname.builder.Page$6.onClick(Page.java:98)
  at android.view.View.performClick(View.java:4459)
  at android.view.View$PerformClick.run(View.java:18443)
  at android.os.Handler.handleCallback(Handler.java:733)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5128)
  at java.lang.reflect.Method.invokeNative(Native Method:0)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
  at dalvik.system.NativeStart.main(Native Method:0)

这是带错误的片段:

public class Page extends DialogFragment {

private View view;
private ViewHolder holder;
private String name
private Object object;

static class ViewHolder {
    private ImageView a1;
    private TextView a1t;
    private Button close;
    private RelativeLayout a1c;
}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if(view == null)
    {
        view = inflater.inflate(R.layout.kit_page, null);
        holder = new ViewHolder();

        holder.a1c = (RelativeLayout) view.findViewById(...);

        holder.a1 = (ImageView) view.findViewById(...);

        holder.a1t = (TextView) view.findViewById(...);

        holder.close = (Button) view.findViewById(...);

        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    name = getArguments().getString("name", "N/A");

    object = getByName(name);

    holder.a1t.setText(item.getAb1().getName());
    holder.a1.setImageResource(getDrawableByName(1, item.getString()));


    holder.close.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dismiss();
        }
    });

    holder.a1c.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v) {
            final AlertDialog dialog;
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View mView = inflater.inflate(R.layout.ability_page, null);

    (...)

            final AlertDialog.Builder mBuilder = new AlertDialog.Builder(v.getContext());
            mBuilder.setView(mView);
            dialog = mBuilder.create();
            dialog.show();

            Button dismiss = (Button) mView.findViewById(R.id.dismiss);

            dismiss.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }
    });

    return view;
}

0 个答案:

没有答案