从主要活动错误中启动类活动

时间:2011-12-31 19:11:54

标签: java android

出于某种原因,虽然我创建了Speak2类,但我的程序找不到它:

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);
}




}

我也加入了清单:

<Activity android:name="Speak2"/>

但我得到错误:

2-31 11:49:43.860:E / AndroidRuntime(4104):android.content.ActivityNotFoundException:无法找到显式活动类{com.voice.recon / voice.Speak2};你有没有在AndroidManifest.xml中声明这个活动?

是我的代码中的一些路径问题还是?请指教?

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> 

4 个答案:

答案 0 :(得分:0)

是否已将此新活动添加到您的清单文件中?

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>

我希望它有所帮助..

答案 1 :(得分:0)

在android中,要启动活动,必须使用tag将其添加到AndroidManifest.xml文件中。除非这样做,否则运行时会在尝试启动活动时给出错误。

在上面的情况中,错误不是,编译器无法找到您的类。相反,错误是因为您缺少清单中的条目

以下是一些参考网址

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

答案 2 :(得分:0)

声明

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

在您的清单中

<application/>

标签

答案 3 :(得分:0)

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

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