java.lang.ClassCastException:android.app.Application无法强制转换为android.app.Activity

时间:2017-07-09 17:12:50

标签: java android android-activity adapter android-context

Activity act = (Activity)mcontext;
            final Intent callIntent = new Intent(Intent.ACTION_CALL);
            String s = list.get(position).phone;
            callIntent.setData(Uri.parse("tel:"+s));

            Dexter.withActivity(act)
                    .withPermission(Manifest.permission.CALL_PHONE)
                    .withListener(new PermissionListener() {
                        @Override public void onPermissionGranted(PermissionGrantedResponse response) {

                            mcontext.startActivity(callIntent);
                        }
                        @Override public void onPermissionDenied(PermissionDeniedResponse response) {
                            Toast.makeText(mcontext, "Accept call permissions first!",
                                Toast.LENGTH_LONG).show();}
                        @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {/* ... */}
                    }).check();
  

java.lang.ClassCastException:android.app.Application无法强制转换为android.app.Activity

是显示在Activity act = (Activity)mcontext;行的错误。当要执行此代码时,应用程序崩溃。直接将mcontext放入Dexter.withActivity,即使在我运行应用之前也会显示错误。

这是适配器的代码。根活动是:public class HodWithPhoneNumber extends Activity

0 个答案:

没有答案