2014-02-08 43 views
0

Android應用程序總是崩潰,我正在以下崩潰報告

java.lang.NullPointerException 
at lk.digitalarc.elan.MainActivity$CustomDataAdapter.getView(MainActivity.java:168) 
at android.widget.AbsListView.obtainView(AbsListView.java:2263) 
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263) 
at android.widget.ListView.onMeasure(ListView.java:1175) 
at android.view.View.measure(View.java:16497) 
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689) 
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473) 
at android.view.View.measure(View.java:16497) 
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
at android.view.View.measure(View.java:16497) 
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327) 
at android.view.View.measure(View.java:16497) 
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) 
at android.view.View.measure(View.java:16497) 
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916) 
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113) 
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295) 
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) 
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) 
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 
at android.view.Choreographer.doCallbacks(Choreographer.java:574) 
at android.view.Choreographer.doFrame(Choreographer.java:544) 
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 

錯誤開始發生後,我寫了條件碼上的ImageView更新圖片src

ImageView img = (ImageView) v.findViewById(R.id.imgDP); 
// update display pic for message according to content 
if (!burst.getBurstFile().isEmpty()) { 
    img.setImageResource(R.drawable.dp_attachment); 
} else if (!burst.getBurstImg().isEmpty()) { 
    img.setImageResource(R.drawable.dp_pic); 
} 

我知道這看起來似乎很簡單,但對我的生活我無法弄清楚的問題是什麼。

這個應用程序的版本是爲SDK版本14到19構建的。我有一個關於.Empty()函數的暫停,但我不確定。

+0

什麼是168線,哪裏是突發初始化 – Raghunandan

回答

0

根據Adapter.getView()javadocs,您應該始終檢查您的ConvertView v是否爲空。我猜的行參考v ImageView img =(ImageView)v.findViewById(R.id.imgDP);是什麼導致空指針異常。