Articles of nullpointerexception

无法使用null启动服务

我最近编写了一个Android Widget,并在模拟器和我的Galaxy S上进行了测试,它在两者上运行良好,在我发布到Android市场后,我现在收到一些错误报告。 我在Widget类的onUpdate中声明了一个服务,如下所示: if (appWidgetIds != null) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to // this // provider for (int i = 0; i < N; i++) { // Start Service for each instance int appWidgetId = appWidgetIds[i]; Intent active = new Intent(context, […]

将null对象转换为String

我编写了一个android程序,用于从Web服务向tablerow加载值。 但是一个值为null,所以我需要将它转换为字符串。 有人可以告诉我这样做的方法。 try{ SoapObject request = service.getRequest(); SoapSerializationEnvelope envelope = service.getEnvelope(request); SoapObject response = service.getResponse(envelope); Log.i(“Service Master”, response.toString()); int count = response.getPropertyCount(); for (int i = 0; i < count; i++) { SoapObject result = (SoapObject) response.getProperty(i); DeleteuserDetails deleteuserDetails=new DeleteuserDetails(); deleteuserDetails.setUserId(result.getPropertyAsString(4)); deleteuserDetails.setUserName(result.getPropertyAsString(2)); deleteuserDetails.setUserRole(result.getPropertyAsString(3)); deleteuserDetails.setCreatedDate(result.getPropertyAsString(1)); deleteuserDetails.setCreatedBy(result.getPropertyAsString(0)); userdetail.add(deleteuserDetails); } 现在deleteuserDetails.setCreatedBy(result.getPropertyAsString(0)); 从webservice获取null值,所以我需要将其转换为字符串”null” 。 logcat的: 12-20 18:48:52.608: W/System.err(2174): […]

在ACTION_GET_CONTENT意图之后有时不会调用OnActivityResult

我正在开发一个图像编辑Android应用程序。 在我的一个活动中,我打算从onCreate中的图库中选择一个图像,如下所示: Intent intent = new Intent(); intent.setType(“image/*”); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, “Select Picture”), PICK_IMAGE); 然后我收到这样的数据: @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Crashlytics.log(“onActivityResult called”); super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK && data != null) { Crashlytics.log(“Data received from image pick intent”); imageUri = data.getData(); loadImage(); } else { […]

IllegalStateException:Fragment 当前不在FragmentManager中

我无法在我的应用中跟踪崩溃的原因。 我有一个显示ListView的片段,我也有SlidingMenu用于搜索字段。 当我搜索时, ListView项目将根据搜索结果重新填充。 现在,当我尝试从新填充的结果中打开ListView项时,我的应用程序崩溃了。 此处触发exception: @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); getSupportFragmentManager().putFragment(outState, “mContent”, mContent); //Exception made here } 这是因为支持库吗? 我该如何解决这个问题? 编辑: 这是堆栈跟踪: 02-05 12:51:53.941: E/AndroidRuntime(11638): FATAL EXCEPTION: main 02-05 12:51:53.941: E/AndroidRuntime(11638): java.lang.IllegalStateException: Fragment MyFragment{436749b0} is not currently in the FragmentManager 02-05 12:51:53.941: E/AndroidRuntime(11638): at android.support.v4.app.FragmentManagerImpl.putFragment(FragmentManager.java:546) 02-05 12:51:53.941: E/AndroidRuntime(11638): at com.sample.android.app.SearchListActivity.onSaveInstanceState(SearchListActivity.java:118) 02-05 12:51:53.941: E/AndroidRuntime(11638): […]

我当前的位置始终返回null。 我怎样才能解决这个问题?

我想find一个Android项目的当前位置。 加载应用程序时,我的当前位置始终为null。 我在清单等中设置了权限。当我find当前位置时,我打算使用坐标来查find地图上其他位置的距离。 我的代码片段如下。 为什么我总是得到一个空值? locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); towers = locMan.getBestProvider(crit, false); location = locMan.getLastKnownLocation(towers); if (location != null) { System.out.println(“Location is not null!”); lat = (int) (location.getLatitude() *1E6); longi = (int) (location.getLongitude() * 1E6); GeoPoint ourLocation = new GeoPoint(lati, longi); OverlayItem overlayItem = new OverlayItem(ourLocation, “1st String”, “2nd […]

Android SQLite空指针exception

我在LogCat中得到这个: 05-20 17:16:34.721: E/AndroidRuntime(30461): FATAL EXCEPTION: main 05-20 17:16:34.721: E/AndroidRuntime(30461): java.lang.NullPointerException 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:290) 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:96) 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1810) 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1761) 05-20 17:16:34.721: E/AndroidRuntime(30461): at com.kickinglettuce.debtplannerpro.DebtDataSource.updateDebt(DebtDataSource.java:130) 05-20 17:16:34.721: E/AndroidRuntime(30461): at com.kickinglettuce.debtplannerpro.manageDebts$4.onClick(manageDebts.java:184) 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.view.View.performClick(View.java:3511) 05-20 17:16:34.721: E/AndroidRuntime(30461): at android.view.View$PerformClick.run(View.java:14105) 05-20 17:16:34.721: E/AndroidRuntime(30461): at […]

DialogFragment:NullPointerException(支持库)

我正在使用优秀的ACRA库从我的应用程序接收错误报告。 我收到了很多客户关于DialogFragment中的NPE的报告,但是我无法重现它: java.lang.NullPointerException at android.support.v4.app.DialogFragment.onActivityCreated(SourceFile:366) at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:892) at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1083) at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1065) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:1844) at android.support.v4.app.FragmentActivity.onStart(SourceFile:519) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133) at android.app.Activity.performStart(Activity.java:4475) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) NPE发生在支持库内 (@line 366): 353 @Override 354 public void onActivityCreated(Bundle savedInstanceState) […]

NullPointerException:尝试在空对象引用上调用虚方法’boolean java.lang.String.equalsIgnoreCase(java.lang.String)’

我在运行时收到此错误。 java.lang.RuntimeException:无法启动活动ComponentInfo java.lang.NullPointerException:尝试在空对象引用上调用虚方法’boolean java.lang.String.equalsIgnoreCase(java.lang.String)’ 堆栈跟踪: 01-12 03:44:54.270: E/AndroidRuntime(1437): FATAL EXCEPTION: main 01-12 03:44:54.270: E/AndroidRuntime(1437): Process: home.saket, PID: 1437 01-12 03:44:54.270: E/AndroidRuntime(1437): java.lang.RuntimeException: Unable to start activity ComponentInfo{home.saket/home.saket.addmember.Add_Update_User}: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equalsIgnoreCase(java.lang.String)’ on a null object reference 01-12 03:44:54.270: E/AndroidRuntime(1437): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 01-12 03:44:54.270: E/AndroidRuntime(1437): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 01-12 03:44:54.270: E/AndroidRuntime(1437): at android.app.ActivityThread.access$800(ActivityThread.java:144) […]

第二次显示ViewPager时出现NullPointerException

我正在使用一个ViewPager片段,它有两个片段作为子片段。 这很好用,但是当我用另一个片段替换ViewPager片段并用ViewPager片段替换这个片段时,我的应用程序崩溃时出现以下NullPointerException : java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.util.ArrayList.size()’ on a null object reference at android.support.v4.app.FragmentManagerImpl.getFragment(FragmentManager.java:667) at android.support.v4.app.FragmentStatePagerAdapter.restoreState(FragmentStatePagerAdapter.java:211) at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1319) at android.view.View.dispatchRestoreInstanceState(View.java:13756) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2888) at android.view.View.restoreHierarchyState(View.java:13734) at android.support.v4.app.Fragment.restoreViewState(Fragment.java:468) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1094) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5294) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) […]

尝试使用getChildAt()取消选择视图

我在ExpandableListView使用GridView 我有一个function,当它被点击时突出显示一个项目,现在我正在尝试实现一个按钮,当按下它时将取消选择所有选定的项目,但它只取消选择最后一个查看的视图 public class GridAdapter extends BaseAdapter { private Context mContext; private ArrayList child; public ArrayList escola; private ArrayList<ArrayList> filhos = new ArrayList(); public GridAdapter(Context context, ArrayList groups, ArrayList childValues, int groupPosition) { mContext = context; child = childValues; escola = groups; posicaoEscola = groupPosition; } @Override public int getCount() { return child.size(); } @Override […]