调试有时会很痛苦,上面的问题是由我原始代码中一个简单的错误导致的。人都会犯错...
现在来看解决方案。我的初始代码如下,如果你仔细看,你会注意到在检查
Build.Version
的if语句之间的初始化代码不会在设备版本低于23的情况下运行。
if(Build.VERSION.SDK_INT >= 23) {
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
initialization();
} else {
if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show();
}
requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE);
}
}
这是初始化方法。在Android版本低于23的设备上,它不会运行,从而触发Could not find class
错误。然而,我仍然没有弄清楚这与Ripple Drawable有什么关系,因为我在代码中没有使用矢量可绘制对象。因此,任何阅读此内容的人可能会对原因有所启示。
private void initialization() {
hoverView = (View) findViewById(R.id.hoverView);
hoverView.setVisibility(View.GONE);
mExitAppDialog = new HookUpDialog(this);
mExitAppDialog.setMessage(getString(R.string.exit_app_message));
mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_OK,
new OnClickListener() {
@Override
public void onClick(View v) {
mExitAppDialog.dismiss();
if (WallActivity.getInstance() != null) {
WallActivity.getInstance().finish();
}
sInstance.finish();
Toast.makeText(getApplicationContext(),
R.string.press_back_again_to_exit,
Toast.LENGTH_SHORT).show();
}
});
mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_CANCEL,
new OnClickListener() {
@Override
public void onClick(View v) {
mExitAppDialog.dismiss();
}
});
mLlRecentActivity = (LinearLayout) findViewById(R.id.llRecentActivity);
mNoActivitiesView = (TextView) findViewById(R.id.tvNoRecentActivities);
}
现在是完整的代码,包括针对Android版本23及以下设备的else if修复。
if(Build.VERSION.SDK_INT >= 23) {
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
initialization();
} else {
if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show();
}
requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE);
}
} else if (Build.VERSION.SDK_INT < 23 ) {
initialization();
}
感谢 @Anurag Singh 的帮助,经过数小时的测试和反复测试,我终于看到了这个结果。不断地搜索和查找。