Android ClassCastException by referencing fragment in viewmodel
Android ClassCastException by referencing fragment in viewmodel I was having some problem when trying to reference the fragment in my viewmodel class. Here is the part where my fragment call the viewmodel: @Click(R.id.buttonExport) void buttonExportClicked(View v){ SummaryViewModel summaryViewModel = ViewModelProviders.of(this).get(SummaryViewModel.class); summaryViewModel.export(webViewResult); } In the viewmodel where I tried to access the context as well as Activity: public void exportSelfTestSummary(WebView webViewResult) { Activity context = (Activity) getApplication().getApplicationContext(); final ProgressDialog progressDialog=new ProgressDialog(context); progressDialog.show(); PdfView.createWebPrintJob(context, webViewResult, directory, fileName, new PdfView.Callback() { .... } And the error message I am getting: 07-02 02:34:01.922 3563-3563/com.mainapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mainapp, PID: 3563 java.lang.ClassCastExc...