Androidの疑难杂症之加载布局报Error inflating class <unknown>

android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

出现这种错误有可能是,你的布局当中某个wedget的属性出错,比如引用了?attr/xxxx,但是你的主题里面却没有给这个attr赋值。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llPlaceHolderLoading"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="?attr/primary_page_background"
    android:gravity="center"
    android:orientation="vertical"
    android:visibility="visible" >

    <ProgressBar
        style="@style/AppTheme.Widget.Progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" />

    <TextView
        android:id="@+id/tvLoadTip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="?attr/loading_tip"
        android:textColor="@color/progress_tips_text_color"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

像这样的在style里面没有把attr赋值,这个界面是加载不错来,并且报错

02-03 17:24:50.746: E/AndroidRuntime(10702): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.realtor.app.extranet.cmls/net.realtor.app.extranet.cmls.ui.activity.TestActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.ProgressBar

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>demo</description> <properties> <java.version>17</java.version> <langchain4j.version>1.0.0-beta3</langchain4j.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-bom</artifactId> <version>${langchain4j.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-community-bom</artifactId> <version>${langchain4j.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.13.0</version> <!-- 最新稳定版 --> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.4</version> <!-- 与 Spring Boot 3.5.0 兼容的版本 --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.18.0</version> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-community-dashscope-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.jetbrains</groupId> <artifactId>annotations</artifactId> <version>24.0.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-reactor</artifactId> </dependency> <!-- 添加响应式编程和流处理的支持 --> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-core</artifactId> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>dev.langchain4j</groupId> <artifactId>langchain4j-easy-rag</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
最新发布
07-16
<think>我们参考了站内引用,特别是引用[1][3][4]中提到的问题:在IDEA中启动Maven项目时,错“程序包lombok.extern.slf4j不存在”,但Maven依赖配置正确。这通常是由于IDEA的构建机制与Maven不协调导致的。 根据引用[3][4]的解决方案,我们可以通过配置IDEA,将构建和运行操作委托给Maven来解决。以下是详细步骤: ### 解决方案 1. **打开IDEA设置**: - 点击菜单栏的 `File` > `Settings`(Windows/Linux)或 `IntelliJ IDEA` > `Preferences`(macOS)。 2. **找到构建工具设置**: - 在设置窗口中,导航到:`Build, Execution, Deployment` > `Build Tools` > `Maven` > `Runner`。 3. **勾选委托选项**: - 在右侧面板中找到 `Delegate IDE build/run actions to Maven` 选项,并勾选它(如下图所示)。 ![Delegate to Maven选项位置](https://example.com/maven-delegate-setting.png) [^3][^4] 4. **应用更改**: - 点击 `Apply` 或 `OK` 保存设置。 5. **重新构建项目**: - 清除现有构建:`Build` > `Clean Project`。 - 重新编译:`Build` > `Rebuild Project`。 ### 为什么需要这样做? - **根本原因**:IDEA默认使用自身的构建系统(而非Maven)执行编译和运行操作。当项目依赖Lombok等编译时代码生成工具时,IDEA的构建系统可能无法正确处理注解,导致包路径解析失败[^3][^4]。 - **委托给Maven**:勾选该选项后,IDEA会将构建任务完全交给Maven处理,确保与`pom.xml`配置一致,避免路径解析错误。 ### 补充验证步骤 如果问题仍未解决,请检查: - **Lombok插件是否启用**: 在IDEA中安装并启用Lombok插件(`File` > `Settings` > `Plugins`,搜索`Lombok`并启用)。 - **注解处理器配置**: 确保注解处理已开启:`Settings` > `Build, Execution, Deployment` > `Compiler` > `Annotation Processors`,勾选 `Enable annotation processing`。 > **注意**:此方案专治“编译不错但运行时包不存在”的疑难杂症,尤其适用于IDEA+Maven组合[^1][^2]。 §§相关问题§§ 1. 如何在Eclipse中解决类似Lombok包不存在的问题? 2. Maven项目如何统一管理依赖版本? 3. Spring Boot项目中如何配置多模块的Lombok依赖?</think>### 解决 Spring Boot Maven 项目中 "程序包 lombok.extern.slf4j 不存在" 的方案 根据引用内容[1][2][3][4],此问题通常是由于 IDE 构建机制与 Maven 不协调导致的。以下是已验证的解决方案: #### 核心解决方案:配置 IDEA 的 Maven 委托设置 1. **打开设置**: - 菜单路径:`File` > `Settings` (Windows/Linux) 或 `IntelliJ IDEA` > `Preferences` (macOS) 2. **修改 Maven 运行配置**: - 导航到:`Build, Execution, Deployment` > `Build Tools` > `Maven` > `Runner` - ✅ 勾选 **Delegate IDE build/run actions to Maven**(关键步骤)[^3][^4] - ✅ 勾选 **Use the same JDK for imports** 3. **应用更改**: ```mermaid graph LR A[保存设置] --> B[清除缓存] B --> C[重新构建项目] ``` - 清除缓存:`File` > `Invalidate Caches` > `Invalidate and Restart` - 重新构建:`Build` > `Rebuild Project` #### 辅助解决方案:验证项目配置 1. **检查 Lombok 依赖**(pom.xml): ```xml <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.30</version> <!-- 推荐版本 --> <scope>provided</scope> </dependency> ``` 2. **启用注解处理**: - 路径:`Settings` > `Build Tools` > `Compiler` > `Annotation Processors` - ✅ 勾选 **Enable annotation processing** 3. **验证插件安装**: - 在插件市场(`Plugins`)中确认 **Lombok** 插件已启用 #### 问题根源分析 当出现此错误时,通常是因为: 1. IDEA 使用自己的构建系统而非 Maven[^1] 2. IDE 缓存未更新 Lombok 生成的代码[^2] 3. 注解处理未正确启用[^3] > **关键提示**:勾选 `Delegate IDE build/run actions to Maven` 可确保构建过程完全遵循 pom.xml 配置,避免 IDE 与 Maven 的构建机制冲突[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值