Java 在Android上的旧版本上开发的项目有什么问题。ClassNotFound异常被抛出!为什么?

Java 在Android上的旧版本上开发的项目有什么问题。ClassNotFound异常被抛出!为什么?,java,android,classnotfoundexception,Java,Android,Classnotfoundexception,有一个简单的TTS(文本到语音)代码示例,我喜欢在Android 4.0上运行。代码如下: package az.tts; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; import android.view.View; import andr

有一个简单的TTS(文本到语音)代码示例,我喜欢在Android 4.0上运行。代码如下:

package az.tts;

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TexttoSpeech extends Activity implements OnInitListener {
    /** Called when the activity is first created. */
     private EditText text;
     private TextToSpeech tts;
     private String str="Hello Android!";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tts = new TextToSpeech(this, this);
        text = (EditText) findViewById(R.id.EditText01);
        //text.setText("Press me");
        str = text.getText().toString();

        Button btn = (Button)findViewById(R.id.Button01);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                str = text.getText().toString();
                tts.speak(str, TextToSpeech.QUEUE_FLUSH, null );
                Toast.makeText(TexttoSpeech.this, text.getText().toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onInit(int status) {
        // TODO Auto-generated method stub
        tts.speak(str, TextToSpeech.QUEUE_FLUSH, null );
        Toast.makeText(TexttoSpeech.this, text.getText().toString(), Toast.LENGTH_SHORT).show();
    }   
}
这是我在LogCat窗口看到的错误:

E/AndroidRuntime(592): java.lang.RuntimeException: Unable to instantiate activity
    ComponentInfo{az.tts/az.tts.TexttoSpeech}: java.lang.ClassNotFoundException:
    az.tts.TexttoSpeech

怎么了?解决方案是什么?

我之前在Android 1.6上编译了这个项目,现在我使用eclipse将它导入到我的工作区,我得到了ClassNotFound异常。刚刚创建了一个新项目,使用了相同的代码,它被编译并成功执行。为什么?可能jar或类文件没有正确地包含在构建路径中。如果没有更多的信息,就不可能说。您是否已在清单中声明该活动?或者,您可能正在使用第二个库,该库具有相同的函数名,并且仅存在于android 4.0上。在使用az.tts.TexttoSpeech时,请尝试使用整个名称空间