我有一个数组,现在我想创建该数组的副本,以便可以保留数组的先前值。
我试过这样的事情:
System.arraycopy(firstArray, 0, secondArray, 0, firstArray.length);
但它给了我一个NullPointerException
,即:
08-26 13:20:08.421: E/AndroidRuntime(23739): FATAL EXCEPTION: main
08-26 13:20:08.421: E/AndroidRuntime(23739): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.iweentravel/com.android.iweentravel.MainAcvtivity}: java.lang.NullPointerException: dst == null
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread.access$600(ActivityThread.java:149)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.os.Looper.loop(Looper.java:153)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread.main(ActivityThread.java:4987)
08-26 13:20:08.421: E/AndroidRuntime(23739): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 13:20:08.421: E/AndroidRuntime(23739): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 13:20:08.421: E/AndroidRuntime(23739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-26 13:20:08.421: E/AndroidRuntime(23739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-26 13:20:08.421: E/AndroidRuntime(23739): at dalvik.system.NativeStart.main(Native Method)
08-26 13:20:08.421: E/AndroidRuntime(23739): Caused by: java.lang.NullPointerException: dst == null
08-26 13:20:08.421: E/AndroidRuntime(23739): at java.lang.System.arraycopy(Native Method)
08-26 13:20:08.421: E/AndroidRuntime(23739): at com.android.iweentravel.MainAcvtivity.onCreate(MainAcvtivity.java:99)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.Activity.performCreate(Activity.java:5020)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-26 13:20:08.421: E/AndroidRuntime(23739): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
08-26 13:20:08.421: E/AndroidRuntime(23739): ... 11 more
请建议我如何正确创建数组的副本。