我在按钮的insideOnclick方法中初始化加载器但是没有这样做并且在传递“null”时得到第三个最后一个参数的错误它在传递“this”时给出了错误< / strong>也没能做好工作。
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(userName.getText().length() == 0 || password.getText().length() == 0)
{
Toast.makeText(context,"UserName Or Password Should be Filled",Toast.LENGTH_SHORT).show();
}
else{
userName.setText("");
password.setText("");
**getLoaderManager().initLoader(1,null,null);** //here is the error
}
}
});
}
@Override
public Loader<User> onCreateLoader(int id,Bundle args) {
loginLoader = new LoginLoader(context,userName.getText().toString(),password.getText().toString(),"2013-07-10 01:18:26");
Log.i("login loader",""+loginLoader);
return loginLoader;
}
@Override
public void onLoadFinished(Loader<User> arg0,User proposals) {
Log.i("User",""+proposals.getUsername());
}
这是错误列表:
01-27 23:27:33.480:E / AndroidRuntime(7777):致命异常:主要 01-27 23:27:33.480:E / AndroidRuntime(7777):java.lang.NullPointerException 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.app.LoaderManagerImpl.createLoader(LoaderManager.java:544) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.app.LoaderManagerImpl.createAndInstallLoader(LoaderManager.java:553) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.app.LoaderManagerImpl.initLoader(LoaderManager.java:607) 01-27 23:27:33.480:E / AndroidRuntime(7777):at com.mrfs.android.surveyapp.activities.LoginActivityService $ 1.onClick(LoginActivityService.java:58) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.view.View.performClick(View.java:4211) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.view.View $ PerformClick.run(View.java:17267) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.os.Handler.handleCallback(Handler.java:615) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.os.Handler.dispatchMessage(Handler.java:92) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.os.Looper.loop(Looper.java:137) 01-27 23:27:33.480:E / AndroidRuntime(7777):在android.app.ActivityThread.main(ActivityThread.java:4898) 01-27 23:27:33.480:E / AndroidRuntime(7777):at java.lang.reflect.Method.invokeNative(Native Method) 01-27 23:27:33.480:E / AndroidRuntime(7777):at java.lang.reflect.Method.invoke(Method.java:511) 01-27 23:27:33.480:E / AndroidRuntime(7777):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006) 01-27 23:27:33.480:E / AndroidRuntime(7777):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 01-27 23:27:33.480:E / AndroidRuntime(7777):at dalvik.system.NativeStart.main(Native Method) * 编辑代码:登录列表SERVICE.JAVA *
public class LoginListService
{
SurveyDBHelper surveyDBHelper;
private final static LoginListService INSTANCE = new LoginListService();
public LoginListService()
{}
public static LoginListService getLoginInstance()
{return INSTANCE;
}
public User getLoginResult(String userName, String password,
String apkVersion) {
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
formData.add("username", "kong");
formData.add("password", "kongkong");
formData.add("apkStatusDate", "2013-07-10 01:18:26"); // **HERE IS THE ERROR**
System.out.print("form data values:" + formData);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(
formData, WorkflowRestService.getInstance().getRequestHeaders());
ResponseEntity<UserListItemHolder> responseEntity = WorkflowRestService
.getInstance()
.getRestTemplate()
.exchange(WorkflowApp.getServicesURL() + "user/logIn",
HttpMethod.POST, requestEntity,
UserListItemHolder.class);
Log.i("response Entity Login", "" + responseEntity);
UserListItemHolder userListItemInstance = responseEntity.getBody();
Log.i("response Entity Body Location Function",
"" + responseEntity.getBody());
if ("true".equals(userListItemInstance.getApkStatus())) {
Log.i("locationInstance.getLocationListItems if", ""+ userListItemInstance.getUserListItems());
return userListItemInstance.getUserListItems();
} else {
Log.i("locationInstance.getLocationListItems else", ""+ userListItemInstance.getUserListItems());
userListItemInstance = null;
return userListItemInstance.getUserListItems();
}
}
答案 0 :(得分:1)
查看您的代码和标记时,会出现NullPointerException
,因为您传递了null
代替必需的参数。
getLoaderManager().initLoader(1,null,null); //here is the error
根据LoaderManager Docs,需要回调:
参数
看起来你已经在实施LoaderCallbacks了,你只需要将你的实现传递给initLoader
方法:
getLoaderManager().initLoader(1,null,this);
答案 1 :(得分:0)
您的日期格式错误。请改用:
2013-02-03T06:41:41.000Z
你必须在日期和时间之间加一个T,在结尾之间加一个Z,然后加上毫秒。