Android之关于json导包报错提示冲突的问题Program type already present(已解决)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Anthony__Lee/article/details/88236331

1、遇到问题:导包后eclipse正常运行,Android studio报错

前几天在做一个项目,客户端要接受从服务器发过来的数据,服务器的小伙伴发给我的json格式的数据,我习惯在eclipse把小模块先测试一下再写进Android studio中去,关于接收并遍历json数据这块在eclipse上能够通过导包以完成相应的操作。

导入了以下包:

commons-beanutils-1.8.0.jar

commons-collections-3.2.1.jar

commons-lang-2.5.jar

commons-logging-1.1.1.jar

ezmorph-1.0.6.jar

json-lib-2.4-jdk15.jar

当然还有  import net.sf.json.JSONObject;

但是当复制进Android studio的时候,IDE就开始报错,如下:

 

这个错误的意思是,这个包中的一些文件和其他的包中的冲突了。可以发现是commons-beanutils-1.8.0.jar包中有和commons-collections-3.2.1.jar冲突的类。

2、解决方法:

(1)在Android自带的Library中导入需要的包(想到这种解决办法是在想Android官方自带的包应该不会有冲突的)

关于导包的方法,这里贴个链接:Androidstudio中添加jar包的方法   用方法一搜索commons-beanutils:commons-beanutils:20030211.134440和commons-collections:commons-collections:20040616即可(数字部分没必要完全一样)

(2)简单粗暴的删除掉那个多余的类。

直接把commons-beanutils-1.8.0.jar解压,然后把解压文件下的org/apache/commons/collections目录和目录下的class直接删掉。但是!删是好删,再压缩成jar包,就不会了,查了好多资料都没搞清楚,所以最后就采用了方法(1)

 

以上。

展开阅读全文

Program type already present: android.support.v4.app.BackStackRecord$Op

04-12

运行代码的时候,出现了这个问题,build报错rn[code=java]Program type already present: android.support.v4.app.BackStackRecord$OprnMessagekind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)[/code]rn虽然不知道具体意思,感觉就是v4包冲突,可是我不会找在哪冲突的rn在网上疯狂搜解决办法,没有一个奏效rn给各位大佬呈上我的build.gradlern[code=text]apply plugin: 'com.android.application'rnrnandroid rn compileSdkVersion 27rn defaultConfig rn applicationId "com.example.asus.bs_im"rn minSdkVersion 16rn targetSdkVersion 27rn versionCode 1rn versionName "1.0"rn testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"rn //use legacy for android 6.0rn useLibrary 'org.apache.http.legacy'rn rn buildTypes rn release rn minifyEnabled falsern proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'rnrn rn rnrnrndependencies rn api fileTree(include: ['*.jar'], dir: 'libs')rn api 'com.android.support.constraint:constraint-layout:1.0.2'rn implementation 'com.android.support:appcompat-v7:27.1.1'rn implementation 'com.android.support:support-v4:27.1.1'rn implementation 'com.squareup.okhttp3:okhttp:3.8.1'rn implementation 'com.google.code.gson:gson:2.8.1'rn testImplementation 'junit:junit:4.12'rn androidTestImplementation 'com.android.support.test:runner:1.0.1'rn androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'rn api project(':easeui')rn configurations all*.exclude group: 'com.android.support', module: 'support-v13' rnrn[/code]rn整了两三个小时了,各种办法都试过了,希望有大佬来拯救一下我这个辣鸡 论坛

The type Employee is already defined?

08-26

[code=Java]package com.test.input;rnrnpublic class ParamTest rnrn public static void main(String[] args) rnrn System.out.println("Testing tripleValue"); rn double percent = 10; rn System.out.println("Before: percent="+percent); rn tripleValue(percent); rn System.out.println("After: percent="+percent); rn System.out.println("\nTesting tripleSalary:"); rn Employee harry = new Employee("Harry",50000); rn System.out.println("Before: salary="+harry.getSalary()); rn tripleSalary(harry); rn System.out.println("After: salary="+harry.getSalary()); rn System.out.println("\nTesting swap:"); rn Employee a = new Employee("Alice",70000); rn Employee b = new Employee("Bob",60000); rn System.out.println("Before: a = "+a.getName()+" "+"b = "+b.getName()); rn swap(a,b); rn System.out.println("After: a = "+a.getName()+" "+"b = "+b.getName()); rn rn rn rn public static void tripleValue(double x) rn rn x=3*x; rn System.out.println("End fo method: x=" +x); rn rn public static void tripleSalary(Employee x) rn rn x.raiseSalary(200); rn System.out.println("End of method: salary ="+x.getSalary()); rn rn rn public static void swap(Employee x,Employee y) rn rn Employee temp = x; rn x = y; rn y = temp; rn System.out.println("End of method: x="+x.getName()+" y="+y.getName()); rn rn rnrn class Employee //The type Employee is already defined.rn rn public Employee (String n, double s) rn rn name = n; rn salary = s; rn rn public String getName() rn rn return name; rn rn public double getSalary() rn rn return salary; rn rn rn public void raiseSalary (double byPercent) rn rn double raise = salary*byPercent/100; rn salary +=raise; rn rn private String name; rn private double salary; rnrn [/code] 论坛

没有更多推荐了,返回首页