当我尝试为ProgressDialog添加自定义视图时出现此错误:
07-23 12:29:27.395: E/AndroidRuntime(9206): FATAL EXCEPTION: main
07-23 12:29:27.395: E/AndroidRuntime(9206): Process: com.app.frisbeee, PID: 9206
07-23 12:29:27.395: E/AndroidRuntime(9206): java.lang.NullPointerException
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.addViewInner(ViewGroup.java:3561)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.addView(ViewGroup.java:3415)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.addView(ViewGroup.java:3391)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.app.Dialog.setContentView(Dialog.java:500)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.app.frisbeee.main_fragment.Main_All_Annonces.onCreate(Main_All_Annonces.java:97)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:823)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:841)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.app.FragmentPagerAdapter.setPrimaryItem(FragmentPagerAdapter.java:130)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.view.ViewPager.populate(ViewPager.java:1066)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.View.measure(View.java:16497)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.View.measure(View.java:16497)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.View.measure(View.java:16497)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.View.measure(View.java:16497)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.Choreographer.doFrame(Choreographer.java:544)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.os.Handler.handleCallback(Handler.java:733)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.os.Handler.dispatchMessage(Handler.java:95)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.os.Looper.loop(Looper.java:136)
07-23 12:29:27.395: E/AndroidRuntime(9206): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-23 12:29:27.395: E/AndroidRuntime(9206): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 12:29:27.395: E/AndroidRuntime(9206): at java.lang.reflect.Method.invoke(Method.java:515)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-23 12:29:27.395: E/AndroidRuntime(9206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-23 12:29:27.395: E/AndroidRuntime(9206): at dalvik.system.NativeStart.main(Native Method)
我在onCreate方法中构建了我的ProgressDIalog:
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
dialog = new ProgressDialog(getActivity());
dialog.setContentView(dialoglayout, null);
dialog.show();
}
和dialoglayout在onCreateView中实例化:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.all_annonces, container, false);
dialoglayout = inflater.inflate(R.layout.dialog_layout, container, false);
return rootView;
}
答案 0 :(得分:0)
onCreate
之前调用 onCreateView
。将成员变量dialoglayout
传递给setContentView