View.findViewById(INT)'在空对象引用

时间:2017-04-08 22:03:29

标签: java android nullpointerexception mysql-connector

我是AndroidStudio的新手,我正在使用JDBC lib进行MySQL连接。

编译时没有错误,但是当我运行我的应用时,我收到了这个错误:

  

appname已停止。

谢谢。

  

E / AndroidRuntime:致命异常:主要                                                                                处理:com.example.root14.yourapp,PID:6784                                                                                java.lang.NullPointerException:尝试调用虚方法' android.view.View android.view.View.findViewById(int)'在null对象引用上                                                                                    在com.example.root14.yourapp.tab1.onCreateView(tab1.java:25)                                                                                    在android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)                                                                                    在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)                                                                                    在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)                                                                                    在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)                                                                                    在android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1638)                                                                                    在android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)                                                                                    在android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)                                                                                    在android.support.v4.view.ViewPager.populate(ViewPager.java:1240)                                                                                    在android.support.v4.view.ViewPager.populate(ViewPager.java:1088)                                                                                    在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:700)                                                                                    在android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)                                                                                    在android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1364)                                                                                    在android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:765)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)                                                                                    在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)                                                                                    在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)                                                                                    在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)                                                                                    在android.widget.LinearLayout.measureVertical(LinearLayout.java:758)                                                                                    在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)                                                                                    在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)                                                                                    在com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)                                                                                    在android.view.View.measure(View.java:19731)                                                                                    在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271)                                                                                    在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358)                                                                                    在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607)                                                                                    在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)                                                                                    在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6301)                                                                                    在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:871)                                                                                    在android.view.Choreographer.doCallbacks(Choreographer.java:683)                                                                                    在android.view.Choreographer.doFrame(Choreographer.java:619)                                                                                    在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:857)                                                                                    在android.os.Handler.handleCallback(Handler.java:751)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                    在android.os.Looper.loop(Looper.java:154)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:6077)                                                                                    at java.lang.reflect.Method.invoke(Native Method)   04-08 22:01:09.999 6784-6784 / com.example.root14.yourapp E / AndroidRuntime:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

1 个答案:

答案 0 :(得分:3)

  

java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'android.view.View android.view.View.findViewById(int)'

您是否尝试调试并检查应用程序是否存在上述空指针异常?

似乎代码正在尝试访问content_main.xml或activity_main.xml中不存在的元素。希望这会有所帮助。