将两个arrayList合并为一个不同的类

时间:2012-09-25 06:58:05

标签: android

嗨,我班上有两个listArrays。我想在活动类中使用一个类,但我想将它们放在一个arrayList中,该arrayList存在于我所有应用程序中定义的公共类中。数据名称是数据 我的第一个类包含下一个数组:

//Class1

public static ArrayList<String> array1=new ArrayList<String>();
public static ArrayList<String> array2=new ArrayList<String>();


//Data
public static ArrayList<Class1> getE = new ArrayList<Class1>();

我试图在Activity类中使用class1中的obj来获取listArray中的值但是app在运行时崩溃了。这就是为什么我想将数组的值放在Data类的一个数组中。 接下来我展示了我如何使用该对象:

//ActivityClass
Class1 c1=new Class1();
if(c1.array1.get(1)=="1")
    {
    return ;
     }

第一个问题:如何将array1和array2中的值放入Data类getE中的数组?

第二个问:为什么当我在ActiityClass中使用obj时应用程序崩溃了?

09-25 07:03:04.888: E/UNIVERSITY(645): Size of List Before 0
09-25 07:03:06.948: I/dalvikvm(645): threadid=3: reacting to signal 3
09-25 07:06:54.738: E/AndroidRuntime(645): FATAL EXCEPTION: main
09-25 07:06:54.738: E/AndroidRuntime(645): java.lang.NullPointerException
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.university.app.PersonalHome$1.onItemClick(PersonalHome.java:61)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.university.app.controls.CarouselAdapter.performItemClick(CarouselAdapter.java:261)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.university.app.controls.Carousel.onSingleTapUp(Carousel.java:964)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.GestureDetector.onTouchEvent(GestureDetector.java:568)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.university.app.controls.Carousel.onTouchEvent(Carousel.java:310)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.View.dispatchTouchEvent(View.java:5541)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.View.dispatchPointerEvent(View.java:5721)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.os.Looper.loop(Looper.java:137)
09-25 07:06:54.738: E/AndroidRuntime(645):  at android.app.ActivityThread.main(ActivityThread.java:4424)
09-25 07:06:54.738: E/AndroidRuntime(645):  at java.lang.reflect.Method.invokeNative(Native Method)
09-25 07:06:54.738: E/AndroidRuntime(645):  at java.lang.reflect.Method.invoke(Method.java:511)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-25 07:06:54.738: E/AndroidRuntime(645):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-25 07:06:54.738: E/AndroidRuntime(645):  at dalvik.system.NativeStart.main(Native Method)
09-25 07:18:01.538: E/AndroidRuntime(715):  at java.lang.reflect.Method.invoke(Method.java:511)

0 个答案:

没有答案