我创建了一个对象,我希望能够在另一个Activity中使用,并尝试将其添加到intent中。我正在使用https://stackoverflow.com/a/7827593。
然而,当我运行该程序时,我收到“android.content.ActivityNotFoundException:无法找到显式活动类{com.deryck.helper / com.deryck.helper.SoupLog}的错误;您是否在您的活动中声明了此活动AndroidManifest.xml中?“
我是Android编程的新手,所以我不知道如何处理这个问题。我曾假设只有Activites需要在Manifest中。如果我确实需要添加它,我该怎么做或者我应该做什么来传递这个对象。我完全错了吗?
我的应用程序是一些页面,用于收集用户记录的时间和温度等不同信息。然后在结束时,信息用于显示何时需要采取其他步骤和其他结果。
我用
创建意图
Intent i = new Intent(MainActivity.this, SoupLog.class); i.putExtra("soupObj", soup); startActivity(i);
我的目标是这个
package com.deryck.helper;
import java.io.Serializable;
import java.util.Calendar;
public class SoupLog implements Serializable{
private int lotNumber;
private String soupType;
private Calendar ProductionDate;
private Calendar timeStart;
private Calendar timeLethal;
private Calendar lethalTemp;
private String lethalMonInitials;
private String lethalDOInitials;
private Calendar packageStartTime;
private int firstTemp;
private int midTemp;
private int nextLastTemp;
private int lastTemp;
private Calendar packDoneTime;
private String lastMonInitials;
private String lastDOInitials;
public SoupLog(){
Calendar calendar = Calendar.getInstance();
ProductionDate = calendar;
}
public SoupLog(int lotNumber, String soupType, Calendar calendar ){
this.lotNumber = lotNumber;
this.soupType = soupType;
ProductionDate = calendar;
}
public int getLotNumber(){
return lotNumber;
}
public void setlotNumber(int lotNumber){
this.lotNumber= lotNumber;
}
public String getSoupType(){
return soupType;
}
public void setSoupType(String soupType){
this.soupType= soupType;
}
public void setProductionDate(int productionYear, int productionMonth, int ProductionDay){
ProductionDate.set(productionYear, productionMonth, ProductionDay);
}
public Calendar getProductionDate(){
return ProductionDate;
}
public void setStartTime(Calendar timeStart){
this.timeStart = timeStart;
}
public Calendar getStartTime(){
return timeStart;
}
public void setLethalTime(Calendar timeLethal ){
this.timeLethal = timeLethal;
}
public Calendar getlethalTime(){
return timeLethal;
}
public Calendar getLethalTemp() {
return lethalTemp;
}
public void setLethalTemp(Calendar lethalTemp) {
this.lethalTemp = lethalTemp;
}
public String getLethalMonInitials() {
return lethalMonInitials;
}
public void setLethalMonInitials(String lethalMonInitials) {
this.lethalMonInitials = lethalMonInitials;
}
public String getLethalDOInitials() {
return lethalDOInitials;
}
public void setLethalDOInitials(String lethalDOInitials) {
this.lethalDOInitials = lethalDOInitials;
}
public Calendar getPackageStartTime() {
return packageStartTime;
}
public void setPackageStartTime(Calendar packageStartTime) {
this.packageStartTime = packageStartTime;
}
public int getFirstTemp() {
return firstTemp;
}
public void setFirstTemp(int firstTemp) {
this.firstTemp = firstTemp;
}
public int getMidTemp() {
return midTemp;
}
public void setMidTemp(int midTemp) {
this.midTemp = midTemp;
}
public int getNextLastTemp() {
return nextLastTemp;
}
public void setNextLastTemp(int nextLastTemp) {
this.nextLastTemp = nextLastTemp;
}
public int getLastTemp() {
return lastTemp;
}
public void setLastTemp(int lastTemp) {
this.lastTemp = lastTemp;
}
public Calendar getPackDoneTime() {
return packDoneTime;
}
public void setPackDoneTime(Calendar packDoneTime) {
this.packDoneTime = packDoneTime;
}
public String getLastMonInitials() {
return lastMonInitials;
}
public void setLastMonInitials(String lastMonInitials) {
this.lastMonInitials = lastMonInitials;
}
public String getLastDOInitials() {
return lastDOInitials;
}
public void setLastDOInitials(String lastDOInitials) {
this.lastDOInitials = lastDOInitials;
}
//TODO find other times of interest
public void get2hour(){
//TODO return timePackDone+2 hours
}
}
我的宣言:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deryck.helper"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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="Last">
<intent-filter></intent-filter>
</activity>
<activity android:name="Lethality">
<intent-filter>
</intent-filter>
</activity>
<activity android:name="Middle">
<intent-filter></intent-filter>
</activity>
<activity android:name="Packaging">
<intent-filter></intent-filter>
</activity>
<activity android:name="Results">
<intent-filter></intent-filter>
</activity>
</application>
答案 0 :(得分:0)
您需要向我们展示失败的代码以及AndroidManifest.xml。
从你到目前为止所写的内容,我可以看到你正在尝试使用活动“SoupLog”,而没有在AndroidManifest.xml中定义它。但是,是的,你是对的,只有活动需要在清单中。