简体   繁体   中英

launch class activity from main activity error

For some reason, although i created the class Speak2 , my program does not find it:

public class recon extends Activity implements OnClickListener{
ListView lv;
static final int check = 2000;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voice);
    lv = (ListView)findViewById(R.id.lvVoiceReturn);
    Button b = (Button)findViewById(R.id.bVoice);
    b.setOnClickListener(this);
    }



public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent i = new Intent(recon.this , Speak2.class); 
    startActivity(i);
    }


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub


    super.onActivityResult(requestCode, resultCode, data);
}




}

I have also added to the manifest:

<Activity android:name="Speak2"/>

But i get error:

2-31 11:49:43.860: E/AndroidRuntime(4104): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.voice.recon/voice.Speak2}; have you declared this activity in your AndroidManifest.xml?

is their some path issues in my code or? Please advise?

manifest current code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.voice.recon"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <activity
        android:label="@string/app_name"
        android:name="voice.recon" >

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


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


</application>


</manifest> 

Have added this new Activity to you manifest file ?

Useful guide for Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.namee"
android:versionCode="1"
android:versionName="1.0" >

<application
    android:debuggable="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity
        android:name=".ActivityClassPath"
        android:label="@string/app_name" >
    </activity>
</application>

</manifest>

I hope it helps..

In android, for you to start an activity, you have to add it to the AndroidManifest.xml file using tag. Unless this is done, runtime will give you an error, when attempting to initiate the activity.

In the above case, the error is NOT that, the compiler is unable to find your class. Rather, the error is because you are missing the entry in manifest

Here are some reference URLs

http://developer.android.com/guide/topics/manifest/manifest-intro.html http://developer.android.com/guide/topics/manifest/activity-element.html

Declare

 <activity  android:name=".recon"></activity>

in your manifest between the

<application/>

Tags

尝试将清单中Speak2活动的条目更改为:

<activity android:name="voice.Speak2"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM