我不能为我的生活弄清楚为什么它一直说“无法找到显式活动类com.example.timer.beep。你在Android Manifest中声明了Activity吗?”。据我所知,它已被宣布,我已经遵循我建立的最后一个小应用程序的约定。我的xml文件是小写的,我的.java文件是CamelCase。有没有人有任何其他想法,为什么它会给我这个错误?错误发生在MainActivity.java中的readyToBeep函数中。
主要Activity.java
package com.example.timer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void readyToBeep(View v)
{
Intent intent = new Intent(this, Beep.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Beep.java
package com.example.timer;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Beep extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.buzz);
}
private Context Context;
Timer timer;
public Beep(){};
public Beep(Context Context) {
this.Context = Context;
timer = new Timer();
timer.schedule(new RemindTask(),
0, //initial delay
1*1500); //subsequent rate
}
class RemindTask extends TimerTask {
public void run() {
MediaPlayer mPlayer = MediaPlayer.create(Context, R.raw.beep);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.start();
}
}
public void main(String args[]) {
new Beep();
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.timer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.timer.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.timer.buzz" >
</activity>
</application>
</manifest>
TIA
答案 0 :(得分:2)
unable to find Explicit Activity Class com.example.timer.beep. Have you declared the Activity in your Android Manifest
您的清单中没有声明您的Beep
活动。添加它:
<activity android:name="com.example.timer.Beep" >
</activity>