0

I am trying to open an activity from Listfragment as below

@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        ((MenuActivity)getActivity()).getSlideoutHelper().close();
        Intent myIntent = new Intent(getActivity(), TravellerTimer.class);
        getActivity().startActivity(myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY));

    }

i registered the TimeTraveller activity in manifest file but still its giving ActivityNotFoundException

Below is my log trace

04-19 17:14:00.030: E/AndroidRuntime(12188): FATAL EXCEPTION: main
04-19 17:14:00.030: E/AndroidRuntime(12188): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.vpiabstest/com.example.activity.TravellerTimer}; have you declared this activity in your AndroidManifest.xml?
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivityForResult(Activity.java:3446)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivityForResult(Activity.java:3407)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:674)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivity(Activity.java:3617)

below is my manifest file

< application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <receiver android:name=".service.ActivityService" />
    <receiver
        android:name=".service.StartupService"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

    <activity android:name="SampleActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MenuActivity"
        android:label="@string/app_name"
        android:theme="@style/MenuTheme" >
    </activity>
    <activity
        android:name=".VpiAbsTestActivity"
        android:theme="@style/Theme.VPI" />
    <activity
        android:name="com.example.activity.CreateTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.EditTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.FakeCall"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.ContactList"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.TravellerTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.TimerPrefrence"
        android:configChanges="keyboardHidden|orientation|screenSize" />

< /application>

Any help is appreciated. thanks

stinepike
  • 54,068
  • 14
  • 92
  • 112
hari86
  • 659
  • 2
  • 16
  • 28
  • 1
    Please read your logcat error carefully. It says have you declared this activity in your AndroidManifest.xml? did you do that? – jaga Apr 19 '13 at 12:00
  • `have you declared this activity in your AndroidManifest.xml?` no need to ask – Pragnani Apr 19 '13 at 12:00
  • yes i did registered in manifest – hari86 Apr 19 '13 at 12:04
  • You have written : "i registered the TimeTraveller activity in manifest file but still its giving ActivityNotFoundException". the logcat says com.example.activity.TravellerTimer is not Found. check the Spelling. – SKK Apr 19 '13 at 12:09
  • @Santhosh now its gving classcastexception Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.example.activity.TimerPrefrence 04-19 17:45:20.445: E/AndroidRuntime(15697): at com.example.activity.TravellerTimer.onCreate(TravellerTimer.java:48) 04-19 17:45:20.445: E/AndroidRuntime(15697): at android.app.Activity.performCreate(Activity.java:5206) 04-19 17:45:20.445: E/AndroidRuntime(15697): at – hari86 Apr 19 '13 at 12:16
  • post com.example.activity.TravellerTimer.onCreate pls. – Gabriele Mariotti Apr 19 '13 at 12:37
  • @hari86: class cast exception means you are trying to assign a reference to some other type. for example you might be assigning editText id declared in XML to a textView. paste your TravellerTimer.onCreate() and XML layout file for the same. – SKK Apr 19 '13 at 12:55
  • @Santhosh here are the links to files http://pastebin.com/Pb70fg66 http://pastebin.com/ZnBqQHGG getting exception at line 47 – hari86 Apr 19 '13 at 13:10

3 Answers3

3

Make sure that you have registered the Activity with full correct package name in the manifest

stinepike
  • 54,068
  • 14
  • 92
  • 112
0

Try the current class object using 'this' keyword to call your activity in the intent parameter .

Intent myIntent = new Intent(this.Urcurrentactivity, TravellerTimer.class);      this.Urcurrentactivity.startActivity(myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY));

Your code should also work but by just seeing this quotes, i cant make it sure .

jad
  • 493
  • 3
  • 16
0

By seeing your code in PasteBin:

ArrayList<ActiveTimer> timerLists = new ArrayList<ActiveTimer>();
timerLists = ((TimerPrefrence) getApplication()).viewTimer();

you are trying to cast TimerPrefrence to an ActiveTimer ArrayList. That is the reason you are getting Class cast exception.

SKK
  • 5,261
  • 3
  • 27
  • 39