开发中使用BaseApplication继承Application遇到的问题,做记录

BaseApplication继承Application有什么用就不用说了,

在Activity中通过getApplication()方法获取Application实例转成BaseApplication的时候报

类型转换异常,

解决办法,在AndroidManifest.xml中要在application节点下添加一个name属性,就没事了不知道什么原因

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 IDEA 开发环境使用 Maven 项目时,可以使用 profile 来指定不同的环境。通常情况下,我们会为开发、测试和部署环境创建不同的 profile。具体步骤如下: 1. 在 pom.xml 文件,添加 profile 标签。 ``` <profiles> <profile> <id>dev</id> <properties> <env>dev</env> </properties> </profile> <profile> <id>test</id> <properties> <env>test</env> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> ``` 这里我们创建了三个 profile,分别对应着 dev、test 和 prod 环境。 2. 在 pom.xml 文件,添加 build 标签,并在其引用 profile。 ``` <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>default-copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 这里我们使用 Maven 插件 maven-resources-plugin,将 src/main/resources 目录的资源文件复制到 target/classes 目录,并在复制的过程进行过滤,替换其的占位符。 3. 在 resources 目录,创建三个文件夹 dev、test 和 prod,并在其创建一个名为 application.properties 的文件。 ``` src/main/resources/ ├── dev │ └── application.properties ├── prod │ └── application.properties └── test └── application.properties ``` 这里我们为每个环境创建了一个 application.properties 文件,用于存放该环境的配置信息。 4. 在 application.properties 文件,添加一些配置信息。 ``` server.port=8080 spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=root ``` 这里我们添加了一些常用的配置信息。 5. 在 IDEA 开发环境,选择 Edit Configurations,在其添加一个 Maven 配置。 6. 在 Command line 输入以下命令: ``` clean install -Pdev ``` 这里的 -P 参数表示指定 profile,这里我们指定了 dev 环境。 7. 点击 OK,保存配置。 现在,我们可以在 dev 环境运行项目了。如果需要在其他环境运行项目,只需要更改 Command line 的 profile 参数即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值