关于androidstuio运行程序遇到 Error:(11, 8) 错误: 无法访问HttpEntity 找不到org.apache.http.HttpEntity的类文件解决方法

主要是targetsdk23以上版本不在支持,如果需要使用的话,在build.gradle文件中添加配置:useLibrary "org.apache.http.legacy"


如:


apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary "org.apache.http.legacy"
    defaultConfig {
        applicationId "com.wang.op"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用Quarkus框架创建一个API接口来导出包含中文内容的CSV文件时,你可以按照以下步骤进行操作: 1. 首先,在你的Quarkus项目中添加`org.apache.commons:commons-csv`依赖项,可以在项目的构建工具(如Maven或Gradle)中进行配置。 2. 创建一个包含中文数据的POJO,例如`Person`: ```java public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } // Getter and setter methods } ``` 3. 创建一个继承自`javax.ws.rs.core.Application`的,并在其中注册一个API接口: ```java import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; @Path("/csv") public class CsvResource { @GET @Produces("text/csv") public Response exportCsv() { List<Person> persons = new ArrayList<>(); persons.add(new Person("张三", 25)); persons.add(new Person("李四", 30)); persons.add(new Person("王五", 35)); String csvFilePath = "output.csv"; try (FileWriter writer = new FileWriter(csvFilePath); CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT.withHeader("Name", "Age"))) { for (Person person : persons) { csvPrinter.printRecord(person.getName(), person.getAge()); } csvPrinter.flush(); } catch (IOException e) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity("Error while exporting CSV file: " + e.getMessage()) .build(); } return Response.ok() .entity("CSV file exported successfully.") .header("Content-Disposition", "attachment; filename=\"output.csv\"") .build(); } } ``` 在上述例子中,我们创建了一个`CsvResource`,使用`@Path("/csv")`将该映射到路径`/csv`,并且使用`@GET`注解来定义一个GET请求的API接口。在这个接口中,我们创建了一个`Person`列表,并将数据写入CSV文件。 注意,在`exportCsv`方法中,我们使用了Java 7中的try-with-resources语句来确保文件资源在使用完之后正确关闭。 此外,我们还使用了`@Produces("text/csv")`注解来指定返回的内容型为CSV格式。 最后,我们返回一个`Response`对象,其中包含了成功或失败的消息,并通过设置`Content-Disposition`头来提示浏览器下载生成的CSV文件运行你的Quarkus应用程序并访问`http://localhost:8080/csv`,将会下载名为`output.csv`的文件,其中包含了中文内容的CSV数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值