gpt4 book ai didi

java - list 中未声明的 Activity (显然)

转载 作者:行者123 更新时间:2023-12-02 06:31:26 27 4
gpt4 key购买 nike

我一生都无法弄清楚为什么它一直显示“无法找到显式 Activity 类 com.example.timer.beep。您是否在 Android list 中声明了该 Activity ?”。据我所知,它已经被声明,并且我遵循了我构建的最后一个小应用程序的约定。我的 xml 文件是小写的,我的 .java 文件是驼峰式的。对于为什么它会给我这个错误,有人有任何其他想法吗?错误出在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();
}
}

list

<?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

最佳答案

unable to find Explicit Activity Class com.example.timer.beep. Have you declared the Activity in your Android Manifest

list 中没有声明您的 Beep Activity 。添加它:

<activity android:name="com.example.timer.Beep" >
</activity>

关于java - list 中未声明的 Activity (显然),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20023870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com