0
배경 서비스를 시작하는 phonegap으로 응용 프로그램을 작성 중이며 백그라운드 서비스에서 json 형식으로 모든 사용자 연락처를 가져 오는 방법이 호출됩니다. 다음은안드로이드 장치 오류에서 모든 연락처 가져 오기
http://code.tutsplus.com/tutorials/build-a-contacts-application-with-jquery-mobile-the-android-sdk-part-1--mobile-5727
코드 : 여기
는에서 입수 한과 코드 오전 테스트입니다protected JSONObject initialiseLatestResult() {
// TODO Auto-generated method stub
final String ContactData = ContactUtility.getAllContactDisplaysJSON(getContentResolver());
return null;
}
내가 얻을 :과 같이 다른 클래스에서 호출
public static String getAllContactDisplaysJSON(ContentResolver contentResolver){
// Obtain all ContactDisplay objects from database and sort them
ArrayList<ContactDisplay> list = getAllContactDisplays(contentResolver);
Collections.sort(list);
// Populate the data structure consisting of ContactList-ContactGroup-ContactDisplay objects
// Start with initializing some variables
ContactList contactList = new ContactList();
String key = "";
ArrayList<ContactDisplay> values = new ArrayList<ContactDisplay>();
ContactGroup group = null;
StringWriter writer = new StringWriter();
// Process the list ContactDisplay objects to construct the data structure
if(list != null && !list.isEmpty()){
for(ContactDisplay display:list){
if(!display.getKey().equals(key)){
if(values.size() > 0){
group = new ContactGroup();
group.setKey(key);
group.setValues(values);
contactList.getContacts().add(group);
}
key = display.getKey();
values = new ArrayList<ContactDisplay>();
}
values.add(display);
}
// Add the last group
if(values.size() > 0){
group = new ContactGroup();
group.setKey(key);
group.setValues(values);
contactList.getContacts().add(group);
}
}else{
return EMPTY_CONTACT_LIST;
}
// We have the data structure of ContactList-ContactGroup-ContactDisplay objects where
// contactList is the root level element. Write it to a JSON formatted string using
// org.codehaus.jackson.map.ObjectMapper.
try{
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(writer, contactList);
}catch(Exception e){
return EMPTY_CONTACT_LIST;
}
return writer.toString();
}
logcat의 다음 오류 :
03-01 07:55:25.289: E/AndroidRuntime(11022): FATAL EXCEPTION: main
03-01 07:55:25.289: E/AndroidRuntime(11022): java.lang.RuntimeException: Unable to create service com.mycontacts.MyService: java.lang.NullPointerException
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1966)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:996)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.os.Looper.loop(Looper.java:130)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.app.ActivityThread.main(ActivityThread.java:3735)
03-01 07:55:25.289: E/AndroidRuntime(11022): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 07:55:25.289: E/AndroidRuntime(11022): at java.lang.reflect.Method.invoke(Method.java:507)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
03-01 07:55:25.289: E/AndroidRuntime(11022): at dalvik.system.NativeStart.main(Native Method)
03-01 07:55:25.289: E/AndroidRuntime(11022): Caused by: java.lang.NullPointerException
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.mycontacts.NativeServices.SendPushMsg(NativeServices.java:68)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.mycontacts.MyService.initialiseLatestResult(MyService.java:63)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.initialiseService(BackgroundService.java:299)
03-01 07:55:25.289: E/AndroidRuntime(11022): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.onCreate(BackgroundService.java:129)
03-01 07:55:25.289: E/AndroidRuntime(11022): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1956)
03-01 07:55:25.289: E/AndroidRuntime(11022): ... 10 more
03-01 07:55:25.299: E/AndroidRuntime(11022): [Blue Error Handler] Make Debugging Report file for main
03-01 07:55:25.299: E/AndroidRuntime(11022): java.lang.RuntimeException: Unable to create service com.mycontacts.MyService: java.lang.NullPointerException
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1966)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:996)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.os.Looper.loop(Looper.java:130)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.app.ActivityThread.main(ActivityThread.java:3735)
03-01 07:55:25.299: E/AndroidRuntime(11022): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 07:55:25.299: E/AndroidRuntime(11022): at java.lang.reflect.Method.invoke(Method.java:507)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
03-01 07:55:25.299: E/AndroidRuntime(11022): at dalvik.system.NativeStart.main(Native Method)
03-01 07:55:25.299: E/AndroidRuntime(11022): Caused by: java.lang.NullPointerException
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.mycontacts.NativeServices.SendPushMsg(NativeServices.java:68)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.mycontacts.MyService.initialiseLatestResult(MyService.java:63)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.initialiseService(BackgroundService.java:299)
03-01 07:55:25.299: E/AndroidRuntime(11022): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.onCreate(BackgroundService.java:129)
03-01 07:55:25.299: E/AndroidRuntime(11022): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1956)
03-01 07:55:25.299: E/AndroidRuntime(11022): ... 10 more
03-01 07:55:32.529: I/BackgroundService(11063): Service creating
03-01 07:55:32.529: I/BackgroundService(11063): Initialising the service
03-01 07:55:32.529: W/dalvikvm(11063): threadid=1: thread exiting with uncaught exception (group=0x4017f560)
03-01 07:55:32.529: E/AndroidRuntime(11063): FATAL EXCEPTION: main
03-01 07:55:32.529: E/AndroidRuntime(11063): java.lang.RuntimeException: Unable to create service com.mycontacts.MyService: java.lang.NullPointerException
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1966)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:996)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.os.Looper.loop(Looper.java:130)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.main(ActivityThread.java:3735)
03-01 07:55:32.529: E/AndroidRuntime(11063): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 07:55:32.529: E/AndroidRuntime(11063): at java.lang.reflect.Method.invoke(Method.java:507)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
03-01 07:55:32.529: E/AndroidRuntime(11063): at dalvik.system.NativeStart.main(Native Method)
03-01 07:55:32.529: E/AndroidRuntime(11063): Caused by: java.lang.NullPointerException
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.mycontacts.NativeServices.SendPushMsg(NativeServices.java:68)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.mycontacts.MyService.initialiseLatestResult(MyService.java:63)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.initialiseService(BackgroundService.java:299)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.onCreate(BackgroundService.java:129)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1956)
03-01 07:55:32.529: E/AndroidRuntime(11063): ... 10 more
03-01 07:55:32.529: E/AndroidRuntime(11063): [Blue Error Handler] Make Debugging Report file for main
03-01 07:55:32.529: E/AndroidRuntime(11063): java.lang.RuntimeException: Unable to create service com.mycontacts.MyService: java.lang.NullPointerException
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1966)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:996)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.os.Looper.loop(Looper.java:130)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.main(ActivityThread.java:3735)
03-01 07:55:32.529: E/AndroidRuntime(11063): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 07:55:32.529: E/AndroidRuntime(11063): at java.lang.reflect.Method.invoke(Method.java:507)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
03-01 07:55:32.529: E/AndroidRuntime(11063): at dalvik.system.NativeStart.main(Native Method)
03-01 07:55:32.529: E/AndroidRuntime(11063): Caused by: java.lang.NullPointerException
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:90)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.mycontacts.NativeServices.SendPushMsg(NativeServices.java:68)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.mycontacts.MyService.initialiseLatestResult(MyService.java:63)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.initialiseService(BackgroundService.java:299)
03-01 07:55:32.529: E/AndroidRuntime(11063): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.onCreate(BackgroundService.java:129)
03-01 07:55:32.529: E/AndroidRuntime(11063): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1956)
03-01 07:55:32.529: E/AndroidRuntime(11063): ... 10 more
안드로이드 (자바) 그래서 난 정말
오류에 전체 스택 추적을 게시하면 몇 가지 중요한 비트가 제외됩니다. – JoxTraex
전체 스택 트레이스를 게시했습니다. – Udo
com.mycontacts.NativeServices.SendPushMsg (NativeServices.java:68)에서 NPE @를 사용하고 있습니다. – JoxTraex