Android-getter / setter未传递一个特定的字符串

时间:2018-11-28 03:41:20

标签: java android android-studio-3.0

在MainActivity.java中,我有以下

String keyword = null;
public String getkeyword() {
        return keyword;
    }
    public void setkeyword(String keyword) {
        this.keyword = keyword;
    }

GS

keyword was declared like: public String keyword = GS.getkeyword();
endpoint was specified like: &keyword=" +  keyword

fix was: &keyword=" + MainActivity.GS.getkeyword()

我的问题是onClick执行了我想要的代码,但是它不会设置关键字。 在GS类中,我将关键字声明为“ public String keyword = null;”。 在method1()中执行时,API返回null。

我想这是一个时间问题?我看过其他线程,但没有解决方案。我还有另一个活动可以调整用户设置,并且这些值会正确地通过API传递。

编辑:这就是为什么堆栈溢出具有后期质量准则的原因。我未能提供足够的信息。

在我的课程中:

...
// Sets up a Chrome extension for time travel debugging.
// See https://github.com/zalmoxisus/redux-devtools-extension for more information.
//const devCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const devCompose =  compose;

// Initializes the Redux store with a lazyReducerEnhancer (so that you can
// lazily add reducers after the store has been created) and redux-thunk (so
// that you can dispatch async actions). See the "Redux and state management"
// section of the wiki for more details:
// https://github.com/Polymer/pwa-starter-kit/wiki/4.-Redux-and-state-management
export const store = createStore(
  state => state,
  devCompose(
    lazyReducerEnhancer(combineReducers),
    applyMiddleware(thunk))
);
...

1 个答案:

答案 0 :(得分:1)

使用此

private String keywword;
public String getkeyword() {
    return keyword;
}
public void setkeyword(String keyword) {
    this.keyword = keyword;
}