0

I'm trying to concatenate string values from clientGroupList to make a string variable. I cannot access to the returned variable. I'm working on shareString_8 and shareString_9.

if (uib.getClientProviderType().equals(ParamConstant.CLIENT_TYPE)) {
    // ClientUserの場合の処理
    //SM4|
    String shareString_8 = shareStringList + ":SM" + Constant.SHARE_MODE_CLIENT_GROUP + "|";
    for (int idx = 0; idx < clientGroupList.size(); idx++) {
        
        //SM4|SHARE_CLIENT_GROUP
        shareString_8 =  shareString_8 + clientGroupList.get(idx);
        
    }   
    return shareString_8;
    
} else {
    // ProviderUserの場合の処理
    //SM-1|
    String shareString_9 = shareStringList + ":SM" + Constant.SHARE_MODE_PUBLISH + "|";
    for (int idx = 0; idx < entityListClientGroup.size(); idx++) {

        //SM-1|CLIENT_GROUP_ID
        shareString_9 = shareString_9 + clientGroupList.get(idx);

    }
    return shareString_9;
}

String shareString = providerId + " AND " + "(" + shareString_1 + " OR " + shareString_2 + " OR " + shareString_3
        + " OR " + shareString_4 + " OR " + shareString_5 + " OR " + shareString_6 + " OR " + shareString_7
        + " OR " + shareString_8 + " OR " + shareString_9 + ")";

Highlighted code

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • 1
    Those variables are declared within the if and else branches of your if/else, respectively. Therefore they are out of scope outside of those branches. Declare them outside of the if/else. – JustAnotherDeveloper Dec 14 '20 at 22:32
  • Then I get this Unreachable code error.===================== String shareString = providerId + " AND " + "(" + shareString_1 + " OR " + shareString_2 + " OR " + shareString_3 + " OR " + shareString_4 + " OR " + shareString_5 + " OR " + shareString_6 + " OR " + shareString_7 + " OR " + shareString_8 + " OR " + shareString_9 + ")"; –  Dec 14 '20 at 22:35
  • Please do not use the comments to post code without context. Declaring the variables outside the if/else is the solution to your problem. If in doing so you find another problem, edit your question to state the new problem or ask a new, separate question. – JustAnotherDeveloper Dec 14 '20 at 22:37

0 Answers0