在学习了精彩的教程后,我遇到了一个转换问题。
该应用程序基本上是一个 stackoverflow api,它使用改造并调用以检索问题和问题详细信息等...
这一切都说了又做了,我不知道为什么它的发布时间更长。
cast inn base activity 出了点问题:
基础 Activity
public class BaseActivity extends AppCompatActivity {
private ControllerCompositionRoot mControllerCompositionRoot;
protected ControllerCompositionRoot getCompositionRoot() {
if(mControllerCompositionRoot == null) {
mControllerCompositionRoot = new ControllerCompositionRoot(
((CustomApplication) getApplication()).getCompositionRoot(),
this
);
}
return mControllerCompositionRoot;
}
}
哪个叫客栈这个类(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());
}
}
我会首先理解为什么必须进行转换,这正是我在教程中遵循的内容,但是如果不了解 MVC 等的整个概念以及如何实现它的含义,我几乎无法继续解决这个问题在 Android 应用程序中。
非常欢迎任何帮助和详细说明。
repo - github
最佳答案
在 list 中注册自定义应用程序类。 我检查了 repo,发现自定义类没有注册。因此您的自定义类未用作应用程序类。
关于java.lang.ClassCastException 不确定我所做的转换的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56825137/