Articles of nullpointerexception

ViewPager片段随着时间推移会被破坏?

我正在使用Android的support.v4包来开发包含多个Fragment的ViewPager。 我试图在用户更改页面时隐藏视图。 所以,我实现了一个OnPageChangeListener来监听我的适配器,并在发生页面更改时调用Fragment的update()方法。 但我得到一个NullPointerException ,我无法弄清楚为什么。 这是代码: public class MyActivity extends FragmentActivity implements OnPageChangeListener { private static final int NUM_ITEMS = 2; private ViewPager mPager; private static SpaceAdapter mAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_pager); mAdapter = new SpaceAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); mPager.setOnPageChangeListener(this); […]

尝试在空对象引用上调用虚方法’android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()’

我的应用程序包含4个片段作为使用FragmentPagerAdapter加载到父片段内的制表符。 问题是,当我运行应用程序并按下并重新打开应用程序时,我收到此错误日志: FATAL EXCEPTION: main java.lang.NullPointerException: Attempt to invoke virtual method ‘android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()’ on a null object reference at android.support.v4.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:1949) at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1965) at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:620) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:513) … 父片段内的代码行是: viewPager.setAdapter(adapter); tabLayout.setupWithViewPager(viewPager); 和ViewPage和Adapter都不是空的! 我必须提到我的所有Fragment的生命周期都在管理中,并且在适配器内部发生了null问题!当我使用Activity作为父级而不是Fragment时,同样的适配器工作正常!

android ActivityOptions.isReturning()NullPointerException

在哪种情况下我有 java.lang.NullPointerException:尝试在空对象引用上调用虚方法’boolean android.app.ActivityOptions.isReturning()’ 我无法理解为什么ActivityTransitionState中的 EnterActivityOptions.isReturning()给我null?

Eclipse升级不起作用

我的Eclipse已经停止构建我的Android,所以我删除了旧版本并安装了Indigo。 当我尝试导入Android项目时,我收到此错误: Errors occurred during the build. Errors running builder ‘Android Resource Manager’ on project ‘ACCUWX_HoneyComb’. java.lang.NullPointerException Errors running builder ‘Android Pre Compiler’ on project ‘ACCUWX_HoneyComb’. java.lang.NullPointerException Errors running builder ‘Java Builder’ on project ‘ACCUWX_HoneyComb’. java.lang.NullPointerException 请帮忙!

如何解决这个问题:’运行android lint’问题

在我的项目的任何活动中,如果我做了一些更改,然后保存该活动,我得到消息“运行android lint遇到了问题。” 这是我的错误日志: java.lang.NullPointerException at com.android.ide.eclipse.adt.AdtUtils.workspacePathToFile(AdtUtils.java:466) at com.android.ide.eclipse.adt.internal.lint.EclipseLintClient.getClassPath(EclipseLintClient.java:753) at com.android.tools.lint.client.api.LintClient.getJavaClassFolders(LintClient.java:198) at com.android.tools.lint.detector.api.Project.getJavaClassFolders(Project.java:270) at com.android.tools.lint.client.api.LintDriver.checkIndividualClassFiles(LintDriver.java:977) at com.android.tools.lint.client.api.LintDriver.checkClasses(LintDriver.java:920) at com.android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.java:785) at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.java:661) at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:288) at com.android.ide.eclipse.adt.internal.lint.LintJob.run(LintJob.java:151) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)\ 我不知道如何解决这个问题。

尝试在空对象引用上调用虚方法’int android.text.Layout.getLineCount()’

我随机获得空指针exception,通常它工作,有时它崩溃,我搜索了很多,但没有得到任何帮助,因为没有正确的线从我得到任何帮助, 我也在使用处理程序。 我的logcat错误如下,代码添加在它下面, java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.text.Layout.getLineCount()’ on a null object reference at android.widget.TextView.onMeasure(TextView.java:6703) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17547) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at […]

java.lang.NullPointerException:println需要一条消息

我得到了错误:java.lang.NullPointerException:println在使用这个方法时需要一条消息: lst_info = new HashMap(); SystemDatabaseHandler db = new SystemDatabaseHandler(getApplicationContext()); lst_info = db.getLstInfo(sql_id); SystemDatabaseHandler: public HashMap getLstInfo(int id){ HashMap lst_temp; lst_temp = new HashMap(); String selectQuery = “SELECT * FROM dkr_lst_lst WHERE lst_id = ” + id; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Log.d(“sql_id”, cursor.getString(0)); lst_temp.put(“sql_id”, cursor.getString(0)); […]

getActionBar()setDisplayHomeAsUpEnabled(真)。 在新活动创建时抛出NullPointerException(Google – Basic Tutorial)

我正在遵循本教程并在此代码块的DisplayMessageActivity的onCreate方法中获取NullPointerException: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled(true); //Exception here } 我正在使用NexusOne AVD模板在模拟器上运行应用程序。 当我点击发送按钮并输入一些文字时,我得到了例外。 这是日志: 09-03 23:02:07.586: E/AndroidRuntime(7095): FATAL EXCEPTION: main 09-03 23:02:07.586: E/AndroidRuntime(7095): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myfirstapp/com.mypackage.myfirstapp.DisplayMessageActivity}: java.lang.NullPointerException 09-03 23:02:07.586: E/AndroidRuntime(7095): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 09-03 23:02:07.586: E/AndroidRuntime(7095): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 09-03 23:02:07.586: E/AndroidRuntime(7095): at android.app.ActivityThread.access$600(ActivityThread.java:141) 09-03 […]

启动IntentService的空指针exception

我有一个我想要启动的IntentService。 当我这样做时,它会吐出这个: java.lang.RuntimeException: Unable to start service com.pec.testapp.service.NewsService@406bd940 with Intent { cmp=com.pec.testapp/.service.NewsService }: java.lang.NullPointerException at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2173) … (omitted for brevity) Caused by: java.lang.NullPointerException at android.app.IntentService.onStart(IntentService.java:110) at android.app.IntentService.onStartCommand(IntentService.java:118) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2160) … 10 more 我已经搜索了这个,并查看了尽可能多的类似StackOverflow问题。 然而,有一些微妙的差异,我无法解决。 首先,exception中没有引用任何类。 其次,通过更改上下文或双重检查来确定类似的问题,以确保它不为空。 我有代码检查是不是这样: public Context context; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); context = getApplicationContext(); if(context == null) Log.d(“PECAPP”,”Context is null”); […]

Android Studio v1.2.0启动错误:java.lang.NullPointerException

将Android Studio更新为v1.2.0后。 在启动时,我得到以下日志,无法打开Android Studio。 我正在使用Windows 7-64bit,看起来也像Ubuntu一样错误 此问题也在Android问题中报告,但仍然没有解决方案 java.lang.RuntimeException: java.lang.NullPointerException at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:178) at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:738) at java.awt.EventQueue.access$300(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:699) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:708) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:362) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) Caused by: java.lang.NullPointerException at com.android.tools.idea.welcome.AndroidVirtualDevice.(AndroidVirtualDevice.java:81) at com.android.tools.idea.welcome.InstallComponentsPath.createComponentTree(InstallComponentsPath.java:89) at com.android.tools.idea.welcome.InstallComponentsPath.init(InstallComponentsPath.java:215) at com.android.tools.idea.wizard.DynamicWizardPath.attachToWizard(DynamicWizardPath.java:97) […]