-3
    public class ListViewActivity extends AppCompatActivity

    {
        ListView lv;

        String[] ListItems={"AutoCompleteTextViewActivity","CheckboxActivity","EditTextActivity","ListViewActivity","ProgressBarActivity","RadioButtonActivity","RatingBar2Activity","RatngBarActivity","SeekBarActivity","SpinnerActivity","SwitchActivity","TextViewActivity"};

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_list_view);
            lv=(ListView)findViewById(R.id.listView1);
            ArrayAdapter ad=new ArrayAdapter(ListViewActivity.this,android.R.layout.simple_list_item_1,ListItems);
            lv.setAdapter(ad);

            lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                    Intent i = new Intent(ListViewActivity.this, ListItems[position].getClass());
                    startActivity(i);
                }
            });
        }
    }

i am current learning android studio.i made an app through which i can open my previously created apps by choosing them from a listview widget.it shows an error in the intent line.please tell me where i've have gone wrong.

MY MANIFEST FILE

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.user.re1">

    <application
        android:allowBackup="true"
        android:banner="@mipmap/ic_launcher_round"
        android:icon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".TextViewActivity" />
        <activity android:name=".EditTextActivity" />
        <activity android:name=".RadioButtonActivity" />
        <activity android:name=".CheckboxActivity" />
        <activity android:name=".RatngBarActivity" />
        <activity android:name=".RatingBar2Activity" />
        <activity android:name=".ProgressBarActivity" />
        <activity android:name=".SeekBarActivity" />
        <activity android:name=".SwitchActivity" />
        <activity android:name=".SpinnerActivity"/>
        <activity android:name=".AutoCompleteTextViewActivity">

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  • check your manifest file and see declaration of Activity class – Jaydeep Devda Jun 28 '17 at 05:57
  • Declare your activity in manifest – AbhayBohra Jun 28 '17 at 05:57
  • 3
    Possible duplicate of [android.content.ActivityNotFoundException: Unable to find explicit activity class](https://stackoverflow.com/questions/10908534/android-content-activitynotfoundexception-unable-to-find-explicit-activity-clas) – Sanoop Surendran Jun 28 '17 at 05:58
  • You should declare all the activities in your manifest file. – SripadRaj Jun 28 '17 at 05:59
  • 1
    `ListItems[position].getClass()` - This is not going to return what you think. – Mike M. Jun 28 '17 at 06:06
  • what should i use then? in place of this command. @MikeM. – Aaron Quadros Jun 28 '17 at 06:08
  • That's returning the `String` class. You need to pass the actual `Activity` classes, however you want to do that. For example, you could use an array of `Class`, or maybe use `Class.forName()`, or an `if` or `switch` with the specific `*.class` values, etc. – Mike M. Jun 28 '17 at 06:25
  • @Mike.M thanks alot :D .. i used Class.forName(), but this alone did'nt solve the problem ...i used StringBuilder too and passed the intent ,like this **Intent i = new Intent(ListViewActivity.this, Class.forName(myAction.toString())) ** (myAction was the StringBuilder holding the full address of the Activity).. – Aaron Quadros Jun 28 '17 at 07:56

1 Answers1

0

Add your activity name to your manifest file

<activity android:name=".ListViewActivity"></activity>
Anil
  • 1,605
  • 1
  • 14
  • 24