attribute: attribute is not a string value报错解决:Android中对比string程序

Android打包上传市场时,报错

attribute: attribute is not a string value

后来发现是因为values下的string文件和values-zh下的string没有对应好,有的字符串其中一个有,另一个文件又没有,可能就会出现这种问题。可以用以下java文件对比两个文件,补全相应字符串。

使用方法:
执行以下java文件,file1和file2分别传需要对比的文件路径,执行完后,相应缺少字符串的文件在标签后,会补全相应字符,把字符剪切粘到resource标签内即可

public class Test {

    public static final String encoding = "UTF-8";
    public static String file1 = "C:\\Users\\00lix\\AndroidStudioProjects\\app\\src\\main\\res\\values\\strings.xml";
    public static String file2 = "C:\\Users\\00lix\\AndroidStudioProjects\\app\\src\\main\\res\\values-zh\\strings.xml";

    public static void main(String[] args) {

        comparison(new File(file1),new File(file2),null,null);
        comparison(new File(file2),new File(file1),null,null);
    }


    public static void comparison(File file1,File file2,String str,String lineValue){
        try {
            if(file1.isFile() && file1.exists()){
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file1),encoding);
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;

                boolean flag = false;
                while((lineTxt = bufferedReader.readLine()) != null){
                    String result = getMatchResult(lineTxt);

                    if (!isEmpty(result) && isEmpty(str)) {
                        comparison(file2,null,result,lineTxt);
                    } else {
                        if(result.equals(str)){
                            return ;
                        }
                    }
                }


                if (!isEmpty(str) && file2==null) {
                    System.out.println("杩藉姞鏂囦欢");
                    try {

                        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                                new FileOutputStream(file1,true), encoding));
                        writer.newLine();
                        writer.write(lineValue);
                        writer.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                read.close();
            }else{
                System.out.println("鎵句笉鍒版寚瀹氱殑鏂囦欢");
            }
        } catch (Exception e) {
            System.out.println("璇诲彇鏂囦欢鍐呭鍑洪敊");
            e.printStackTrace();
        }
    }

    public static boolean isEmpty(String str){
        if (str == null || str.length() == 0)
            return true;
        else
            return false;
    }

    public static String getMatchResult(String value){
        if(value.indexOf("name=\"") > 0) {
            int i = value.indexOf("name=\"");
            value = value.substring(i+=6, value.indexOf("\"",i+6));

            return value;
        }
        return "";

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值