0

我收到错误本地变量可能尚未在以下代码行中初始化

final StingBuilder personSearchURLOne = personSearchURLOne.append(getName.getName1(searchOne));

我无法通过最终 StringBuilder personSearchURLOne = null 进行初始化;起初因为我以后将无法更改它所以我试图在我需要它的实例中最终初始化它。它必须是最终的,因为如果它不是我收到错误:无法引用以不同方法定义的内部类中的非最终变量。

这是我的另一堂课

import android.widget.EditText;

public class getName {
static String nameOne = null;
static String nameTwo = null;

static StringBuilder personURLOne = new StringBuilder();
static StringBuilder personURLTwo = new StringBuilder();

public static String personURL = "http://api.themoviedb.org/3/search/person?api_key=bb0b6d66c2899aefb4d0863b0d37dc4e&query=";

public static StringBuilder getName1(EditText searchOne){
    nameOne = searchOne.getText().toString();


    nameOne = nameOne.replace(" ", "_");


    personURLOne.append(personURL); 
    personURLOne = personURLOne.append(nameOne);



    return personURLOne;

}

public static StringBuilder getName2(EditText searchTwo){
    nameTwo = searchTwo.getText().toString();
    nameTwo = nameTwo.replace(" ", "_");

    personURLTwo.append(personURL);
    personURLTwo = personURLTwo.append(nameTwo);

    return personURLTwo;
}


}
4

1 回答 1

2

final StingBuilder personSearchURLOne = new StringBuilder(getName.getName1(searchOne));

于 2012-09-12T19:37:07.310 回答