我对android studio很新,但是我遇到了这个错误,我无法运行我的项目。我看到很多答案建议添加 support-annotations 依赖项,但我使用appcompat所以我不需要它。有什么想法吗?
答案 0 :(得分:0)
您是否拥有Android支持库?
要做到这一点,请将其添加到" app"的build.gradle文件中。模块:
dependencies {
...
implementation "com.android.support:support-annotations:27.1.0"
}
然后同步项目。
有时您可以通过在错误消息上按Alt + Enter并选择解决方案来自动执行此操作。
答案 1 :(得分:0)
您需要获取包含导入内容的库,在模块的构建gradle文件中的依赖性标签内添加以下行:
//Determinant - Only square matrices have a determinant
template <typename T, std::size_t size>
T Determinant(Matrix<T, size, size> &mat)
{
ASSERT(size >= 2, "Wtf? 1x1 matrix?")
T determinant = {};
//Base case - Smallest size of matrix we can calculate the determinant is 2x2
if (size == 2)
{
return ((mat.m_data[0][0] * mat.m_data[1][1]) - (mat.m_data[0][1] * mat.m_data[1][0]));
}
else //otherwise, we need to grab the sub matrix within the current matrix and get the determinate of those.
{
Matrix<T, size - 1, size -1 > subMatrix;
//Note: We're filling in the new sub matrix column order
for (int topRow_ColumnIndex = 0; topRow_ColumnIndex < size; ++topRow_ColumnIndex)
{
int newSubCol = 0;
for (int subCol = 0; subCol < size; ++subCol)
{
int newSubRow = 0;
if (subCol == topRow_ColumnIndex)
{
continue;
}
//Sub matrices will start one row below the top row.
for (int subRow = 1; subRow < size; ++subRow)
{
subMatrix[newSubCol][newSubRow] = mat[subCol][subRow];
++newSubRow;
}
++newSubCol;
}
determinant = determinant + (T)pow(-1, topRow_ColumnIndex) * mat.m_data[topRow_ColumnIndex][0] *Determinant(subMatrix);
}
}
return determinant;
}
或
Matrix<T, size - 1, size - 1 > subMatrix;
其中 X.X.X 是其余支持库的版本。
您应该阅读this article,其中详细介绍了如何实现此目的。