I want to access an arrayList from one activity to another,I have tried as below,But it gives me ClassCast exception, logcat
08-02 11:33:37.438: E/AndroidRuntime(1940): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eps.blancatours/com.eps.blancatours.ui.AddBookingpopupActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.eps.blancatours.ui.DestinationsActivity
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread.access$700(ActivityThread.java:168)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.os.Looper.loop(Looper.java:176)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread.main(ActivityThread.java:5493)
08-02 11:33:37.438: E/AndroidRuntime(1940): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 11:33:37.438: E/AndroidRuntime(1940): at java.lang.reflect.Method.invoke(Method.java:525)
08-02 11:33:37.438: E/AndroidRuntime(1940): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
08-02 11:33:37.438: E/AndroidRuntime(1940): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
08-02 11:33:37.438: E/AndroidRuntime(1940): at dalvik.system.NativeStart.main(Native Method)
08-02 11:33:37.438: E/AndroidRuntime(1940): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.eps.blancatours.ui.DestinationsActivity
08-02 11:33:37.438: E/AndroidRuntime(1940): at com.eps.blancatours.ui.AddBookingpopupActivity.onCreate(AddBookingpopupActivity.java:30)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.Activity.performCreate(Activity.java:5372)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
08-02 11:33:37.438: E/AndroidRuntime(1940): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
destinationActivity.java
public ArrayList<String> names;
names = new ArrayList<String>();
public ArrayList<String> getState() {
return names;
}
public void setState(ArrayList<String> s) {
names = s;
}
secondactivity.java
ArrayList<String> dest;
dest = new ArrayList<String>();
DestinationsActivity appState = ((DestinationsActivity) getApplicationContext());
dest = appState.getState();
0 comments:
Post a Comment