Found the code in the forum, which seems to be all work. After clicking in the console, Exception is displayed. Tell me how to properly handle the button.
In the manifest prescribed:
<uses-permission android:name="android.permission.CALL_PHONE"/> In the adapter:
@Override public void onBindViewHolder(final ViewHolder holder, final int position) { holder.call.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fragmentWelcom.call(position); } }); In the fragment:
public void call(final int position) { try { int number = 23; Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + number); startActivity(intent); } catch (Exception e) { e.printStackTrace(); } } Stacktrace:
W/System.err: java.lang.NullPointerException W/System.err: at com.cholak.v3.appPineapple.fragments.FragmentWelcom.call(FragmentWelcom.java:197) W/System.err: at com.cholak.v3.appPineapple.adapter.RecyclerAdapter$3.onClick(RecyclerAdapter.java:85) W/System.err: at android.view.View.performClick(View.java:4295) W/System.err: at android.view.View$PerformClick.run(View.java:17456) W/System.err: at android.os.Handler.handleCallback(Handler.java:615) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:92) W/System.err: at android.os.Looper.loop(Looper.java:174) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:4952) W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) W/System.err: at dalvik.system.NativeStart.main(Native Method)
catchadd the linee.printStackTrace();and attach the stacktrace to the question - tCodecontactsList.get(position).getPrice()you have anulllooking for an error - tCodetel:/pattern is used. If after correctionNullPointerExceptionstill will not work - try to change the pattern - zTrap