Binary XML file line #6: Error inflating class fragment
大概原因都是因为Class的类型不匹配导致,如下文分析
http://blog.csdn.net/duguang77/article/details/17579847
不过笔者遇到的比较坑是比较深:由ButterKnife引起
对,因为在Gradle中的配置不正确,导致无法正确bindView,在Fragment中出现了NullPointException最后抛出上面异常Binary XML file line #6: Error inflating class fragment。
解决办法:ButterKnife相关的依赖配置不能再library module中配置,而必须要在具体的使用ButterKnife的module中配置才行。
最新配置方法参考官方文档
https://github.com/JakeWharton/butterknife
android:windowBackground 设置图片会变形的问题
大概是ImageView的centerCrop用太多了,于是忘记了.9的存在,大多数情况.9能解决android:windowBackground里面背景图变形的问题。
GitHub push时出现“remote:Repository not found .repository ‘https://github.com/xxxx/xxx’ not found”]
定位原因:github账户我有两个,一个是自己私人用的,另一个是公司用的。之前默认是用的公司的,最近不知道怎没回事,默认的账户变成自己私人的,所以就不能push和pull代码。
解决办法:用ssh协议来控制公司的代码库。(具体方法网上有很多,这里就不做赘述了)
Android Studio报错“Error running ***: Please select Android SDK”
复现路径:笔者的项目有多个分支,其中有个分支是xxxx_demo,在这个分支上我新加了一个module demo用于编写示例,然后切回到没有demo module的主分支上做迭代开发,最后回到这个xxxx_demo分支时,运行demo module时就出现了这个错误信息。
定位原因:经过搜索关键,发现大家分析是IDEA所依赖的Android工程配置文件结构有损坏或丢失,各路大神都是自己手动添加配置回去的,但不同开发者的开发环境是不同的,而且每个人的项目依赖也不同,比如笔者自己的就很复杂,甚至连配置文件都丢失了,无从下手。于是笔者逆向思维一波,既然丢失了就让Android Studio重新初始化环境应该就好了。
解决办法:关闭所有项目(注意不是关闭Android Studio),之后会弹出带有Welcome to Android Studio弹窗,用Open an existing Android Studio project 打开这个项目即可,Android Studio会重新初始化项目所需要的信息
image.png
Android Room 单测 org.junit.internal.runners.rules.ValidationError: The @Rule 'helper' must be public.
Room的官方教程中有这样一段Kotlin代码指导我们如何进行单测
@RunWith(AndroidJUnit4::class)
class MigrationTest {
private val TEST_DB = "migration-test"
@Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MigrationDb::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
)
@Test
@Throws(IOException::class)
fun migrate1To2() {
var db = helper.createDatabase(TEST_DB, 1).apply {
// db has schema version 1. insert some data using SQL queries.
// You cannot use DAO classes because they expect the latest schema.
execSQL(...)
// Prepare for the next version.
close()
}
// Re-open the database with version 2 and provide
// MIGRATION_1_2 as the migration process.
db = helper.runMigrationsAndValidate(TEST_DB, 2, true, MIGRATION_1_2)
// MigrationTestHelper automatically verifies the schema changes,
// but you need to validate that the data was migrated properly.
}
}
定位原因:日志说得很清楚了org.junit.internal.runners.rules.ValidationError: The @Rule 'helper' must be public.
解决办法:参考文章:https://discuss.kotlinlang.org/t/how-can-i-use-rule/304,修改helper声明部分,如下:
@Rule
fun helper(): MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MigrationDb::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()













网友评论