如何针对许多API版本优化应用?

时间:2014-10-16 16:17:49

标签: android android-logcat

我是android中的开发应用程序并使用我的设备与API版本17来运行应用程序,但是当我使用带有API 10的设备时,应用程序在启动时关闭,这是日志。这些错误是什么意思?

E/AndroidRuntime(2336): FATAL EXCEPTION: main
E/AndroidRuntime(2336): java.lang.NullPointerException
E/AndroidRuntime(2336):     at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:263)    
E/AndroidRuntime(2336):     at java.lang.Double.parseDouble(Double.java:318)
E/AndroidRuntime(2336):     at com.gestionderiesgos.sismosecuador.SitesAdapter.getView(SitesAdapter.java:81)    
E/AndroidRuntime(2336):     at android.widget.AbsListView.obtainView(AbsListView.java:1554)
E/AndroidRuntime(2336):     at android.widget.ListView.makeAndAddView(ListView.java:1793)
E/AndroidRuntime(2336):     at android.widget.ListView.fillDown(ListView.java:718)
E/AndroidRuntime(2336):     at android.widget.ListView.fillFromTop(ListView.java:775)
E/AndroidRuntime(2336):     at android.widget.ListView.layoutChildren(ListView.java:1646)
E/AndroidRuntime(2336):     at android.widget.AbsListView.onLayout(AbsListView.java:1384)
E/AndroidRuntime(2336):     at android.view.View.layout(View.java:7228)
E/AndroidRuntime(2336):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
E/AndroidRuntime(2336):     at android.view.View.layout(View.java:7228)
E/AndroidRuntime(2336):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(2336):     at android.view.View.layout(View.java:7228)
E/AndroidRuntime(2336):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(2336):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(2336):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(2336):     at android.view.View.layout(View.java:7228)
E/AndroidRuntime(2336):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(2336):     at android.view.View.layout(View.java:7228)
E/AndroidRuntime(2336):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1145)
E/AndroidRuntime(2336):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
E/AndroidRuntime(2336):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(2336):     at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(2336):     at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(2336):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(2336):     at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(2336):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)    
E/AndroidRuntime(2336):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/AndroidRuntime(2336):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:-1)

您必须设置代码中的条件以防止较低API版本出现空错误 - 例如:

  if (Build.VERSION.SDK_INT < 11) {
   //code 

  } else {
   //code

  }