java - Variable is still null when assigning it a value -
so have code:
string query = null; public string createconnection() { new networkrequest(new resultfromasync() { @override public void taskcompleted(string result) { query = result; } }).execute(); return query; } i following mvp design pattern, called view upon button click event calls method executes , creates network request model , retrieves json string, when debugging on line "query = result;" assigns stored in result variable query when gets line "return query;" equals null.
does understand why setting query null when had been assigned value of result variable?
your method assigns value query executed asynchronously, meaning calling execute() won't block current thread until asynchronous request completes, returns immediately. value of variable still null @ time. cannot return value don't have yet.
consider calling code requires value inside taskcompleted() callback.
Comments
Post a Comment