startActivity not working

纵然是瞬间 提交于 2019-12-24 12:33:40

问题


        public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        //Toast.makeText(getApplicationContext(), "Position of selected item is: "+   position, Toast.LENGTH_LONG).show();

        if ("Abiding in Christ".equals(categories[position]))
                {startActivity(AbidingInChrist.class);}
        else if ("Abundant Living".equals(categories[position]))
                {startActivity(AbundantLiving.class);}
        else if ("Access to God".equals(categories[position]))
                {startActivity(AccessToGod.class);}
        else if ("Adoration of God".equals(categories[position]))
                {startActivity(AdorationOfGod.class);}
        else if ("Amazing Grace".equals(categories[position]))
                {startActivity(AmazingGrace.class);}

all of the startActivity s are underlined in red and want me to change to something or create a method same name. I did add all the activities to the manifest, but some of them didn't work:

  <activity android:name=".AbidingInChrist"</activity>
    <activity android:name=".AbundantLiving</activity>
    <activity android:name=".AccessToGod</activity>
    <activity android:name=".AdorationOfGod</activity>
    <activity android:name=".AmazingGrace</activity>
    <activity android:name=".AnsweredPrayer</activity>
    <activity android:name=".Atonement</activity>
    <activity android:name=".Attitudes</activity>
    <activity android:name=".Belief</activity>
    <activity android:name=".Blessing</activity>
    <activity android:name=".BloodOfJesus</activity>
    <activity android:name=".Boldness</activity>
    <activity android:name=".Brokenness</activity>
    <activity android:name=".Calling</activity>
    <activity android:name=".Comfort</activity>
    <activity android:name=".Commitment</activity>

It's hard to tell here, but every other one was in red saying that it was missing the android namespace prefix.

Appreciate ya'll!


回答1:


In your code try to use an intent to start activity:

   Intent i = new Intent(ACTUALACTIVITY.this, OTHERACTIVITY.class);
                startActivity(i);

and in your manifest put your activity full address (package.activity) like below:

<application>
(...)
            <activity
                android:name="packagename.YOURACTIVITY">
            </activity>
</application>



回答2:


Try to create Intent and start Activity passing this intent like

// Create intent to start new Activity
Intent intent = new Intent(context, YourActivity.class);
startActivity(intent);



回答3:


The startActivity method takes an Intent as parameter. Yo are trying to pass a class and that's why you get the "red underline"

try this:

    if ("Abiding in Christ".equals(categories[position]))
            {startActivity(new Intent(this, AbidingInChrist.class));}
    else if ("Abundant Living".equals(categories[position]))
            {startActivity(new Intent(this, AbundantLiving.class));}
    else if ("Access to God".equals(categories[position]))
            {startActivity(new Intent(this, AccessToGod.class));}
    else if ("Adoration of God".equals(categories[position]))
            {startActivity(new Intent(this, AdorationOfGod.class));}
    else if ("Amazing Grace".equals(categories[position]))
            {startActivity(new Intent(this, AmazingGrace.class));}

Also in you manifest don't forget to close the quotes when you declare an activity

        <activity android:name=".AbidingInChrist"></activity>
        <activity android:name=".AbundantLiving"></activity>
        <activity android:name=".AccessToGod"></activity>

etc



来源:https://stackoverflow.com/questions/24808094/startactivity-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!