0

I have an Android app which includes a dialog fragment that has 4 selections, each leading to an Alert Dialog with additional information On Click.

This functionality is working for my device (Galaxy S7 Edge, Android 7.0), but I am getting reports from users saying their app is crashing when they click a selection (should open the alert dialog).

My diagnostics say that the error is caused by a NoSuchMethodError for the OnClick, only occurring in Android versions 4.4, 5.0, 5.1 (as of now).

Does anyone have any idea what could be causing this issue? It's very hard to troubleshoot since it works on my device.

NOTE: I am using View.OnClickListener if that changes anything.

Error stack trace example:

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)

And here is the fragment with the error:

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;
}
Adam Arcaro
  • 451
  • 7
  • 19
  • Possible duplicate of [Compatibility of getContext and getResource between 5.0 and lower](https://stackoverflow.com/questions/27463737/compatibility-of-getcontext-and-getresource-between-5-0-and-lower) – Phil3992 May 23 '17 at 14:28
  • @Phil3992 Could you kindly suggest how I could resolve this issue? The linked post seems helpful but I don't understand how to apply it to my case – Adam Arcaro May 23 '17 at 14:52

0 Answers0