Ad

Java.lang.ClassCastException Unsure Of Implications Of A Cast I Made

- 1 answer

Following a brilliant tutorial I've come stuck with a casting issue .

The app is basically a stackoverflow api which uses retrofit and makes calls to retrieve questions and question details etc...

This all said and done I'm lost why it longer launches.

stacktrace

Something is wrong with the cast inn the base activity:

BaseActivity

public class BaseActivity extends AppCompatActivity {



    private ControllerCompositionRoot mControllerCompositionRoot;

    protected ControllerCompositionRoot getCompositionRoot() {

        if(mControllerCompositionRoot == null) {

            mControllerCompositionRoot = new ControllerCompositionRoot(
                    ((CustomApplication) getApplication()).getCompositionRoot(),
                    this
            );

        }

        return  mControllerCompositionRoot;
    }
}

which gets called inn this class activity

public class QuestionsListActivity extends BaseActivity implements QuestionsListViewMvcImpl.Listener {

    private StackoverflowApi mStackoverflowApi;
    private QuestionsListViewMvc questionsListViewMvc;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        questionsListViewMvc = getCompositionRoot().getViewMvcFactory().getQuestionListViewMvc(null);

        questionsListViewMvc.registerListener(this);

        mStackoverflowApi = getCompositionRoot().getStackoverflowApi();


        setContentView(questionsListViewMvc.getRootView());
                }

    @Override
    protected void onStart() {
        super.onStart();
        fetchQuestions();
    }

    private void fetchQuestions() {
        mStackoverflowApi.fetchLastActiveQuestions(Constants.QUESTIONS_LIST_PAGE_SIZE)
                .enqueue(new Callback<QuestionsListResponseSchema>() {
                    @Override
                    public void onResponse(Call<QuestionsListResponseSchema> call, Response<QuestionsListResponseSchema> response) {
                        if (response.isSuccessful()) {
                            bindQuestions(response.body().getQuestions());
                        } else {
                            networkCallFailed();
                        }
                    }

                    @Override
                    public void onFailure(Call<QuestionsListResponseSchema> call, Throwable t) {
                        networkCallFailed();
                    }
                } );
    }

    private void bindQuestions(List<QuestionSchema> questionSchemas) {
        List<Question> questions = new ArrayList<>(questionSchemas.size());
        for (QuestionSchema questionSchema : questionSchemas) {
            questions.add(new Question(questionSchema.getId(), questionSchema.getTitle()));
        }
            questionsListViewMvc.bindQuestions(questions);
    }

    private void networkCallFailed() {
        Toast.makeText(this, R.string.error_network_call_failed, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onQuestionClicked(Question question) {
        QuestionDetailsActivity.start(this, question.getId());
    }


}

I would understand first why the cast has to be made which is what I was following in the tutorial buttheres little way I can keep plugging at this wiithout understanding the whole concept of MVC etc..and the implications of how to implement that in an android app.

Any help would be greatly welcome and elaborations as well also.

repo - github

Ad

Answer

Register the custom application class in manifest. I checked the repo and found the custom class is not registered. So your custom class is not used as application class.

Ad
source: stackoverflow.com
Ad