如何从一个方法返回2个值并在一个类中使用这两个值?

如何从一个方法返回2个值并在一个类中使用这两个值?,第1张

概述我正在尝试从Microsoft获得此代码,但我想将它们所做的两个功能结合起来.一个是分析图像,一个是检测名人.但是,我在如何从一个函数返回2个值时遇到困难.这是处理方法……privateStringprocess()throwsVisionServiceException,IOException{Gsongson=newGson();

我正在尝试从Microsoft获得此代码,但我想将它们所做的两个功能结合起来.一个是分析图像,一个是检测名人.但是,我在如何从一个函数返回2个值时遇到困难.
这是处理方法……

private String process() throws VisionServiceException, IOException {    Gson gson = new Gson();    String model = "celebritIEs";    ByteArrayOutputStream output = new ByteArrayOutputStream();    bitmapPicture.compress(Bitmap.CompressFormat.JPEG, 100, output);    ByteArrayinputStream inputStream = new ByteArrayinputStream(output.toByteArray());    AnalysisResult v = this.clIEnt.describe(inputStream, 1);    AnalysisInDomainResult m = this.clIEnt.analyzeImageInDomain(inputStream,model);    String result = gson.toJson(v);    String result2 = gson.toJson(m);    Log.d("result", result);    return result, result2;}

并将这两种结果与这种方法结合起来……

    @OverrIDeprotected voID onPostExecute(String data) {    super.onPostExecute(data);    mEditText.setText("");    if (e != null) {        mEditText.setText("Error: " + e.getMessage());        this.e = null;    } else {        Gson gson = new Gson();        AnalysisResult result = gson.fromJson(data, AnalysisResult.class);        //pang detect ng peymus...        AnalysisInDomainResult result2 = gson.fromJson(data, AnalysisInDomainResult.class);        //decode the returned result        JsonArray detectedCelebs = result2.result.get("celebritIEs").getAsJsonArray();        if(result2.result != null){            mEditText.append("CelebritIEs detected: "+detectedCelebs.size()+"\n");            for(JsonElement celebElement: detectedCelebs) {                JsonObject celeb = celebElement.getAsJsonObject();                mEditText.append("name: "+celeb.get("name").getAsstring() +", score" +                        celeb.get("confIDence").getAsstring() +"\n");            }        }else {            for (Caption caption: result.description.captions) {                mEditText.append("Your seeing " + caption.text + ", confIDence: " + caption.confIDence + "\n");            }            mEditText.append("\n");        }       /* for (String tag: result.description.Tags) {            mEditText.append("Tag: " + tag + "\n");        }        mEditText.append("\n");        mEditText.append("\n--- Raw Data ---\n\n");        mEditText.append(data);*/        mEditText.setSelection(0);    }}

提前致谢!

解决方法:

您可以使用.参数是两个对象,所以你可以放一切

  final Pair<String, String> pair = Pair.create("1", "2");  String a = pair.first;  String b = pair.second;
总结

以上是内存溢出为你收集整理的如何从一个方法返回2个值并在一个类中使用这两个值?全部内容,希望文章能够帮你解决如何从一个方法返回2个值并在一个类中使用这两个值?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1116253.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存