- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下实现 Parcelable 的类。
package com.example.allinone;
import android.accounts.Account;
import android.os.Parcel;
import android.os.Parcelable;
public class WebSiteObject implements Parcelable {
public String webSiteName;
public String webSiteURL;
public WebSiteObject(String webSiteName, String webSiteURL) throws Exception {
this.setWebSiteName(webSiteName);
this.setWebSiteURL(webSiteURL);
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel out, int arg1) {
// TODO Auto-generated method stub
out.writeString(webSiteName);
out.writeString(webSiteURL);
}
public static final Parcelable.Creator<Account> CREATOR = new Parcelable.Creator<Account>() {
public Account createFromParcel(Parcel in) {
return new Account(in);
}
public Account[] newArray(int size) {
return new Account[size];
}
};
public String getWebSiteName() {
return webSiteName;
}
public String getWebSiteURL() {
return webSiteURL;
}
public void setWebSiteName(String webSiteName) {
this.webSiteName = webSiteName;
}
public void setWebSiteURL(String webSiteURL) {
this.webSiteURL = webSiteURL;
}
}
然后我使用以下代码将此类的对象从一个 Activity 传递到另一个 Activity
Intent webActivityLauncher = new Intent(MainActivity.this, WebActivity.class);
webActivityLauncher.putExtra("selectedWebObject", aWebSiteObject);
startActivity(webActivityLauncher);
以下代码可在第二个 Activity 中访问它
WebSiteObject aWebSiteObject = (WebSiteObject)getIntent().getParcelableExtra("selectedWebObject");
但是它不起作用。我在 logcat 中收到以下错误。
05-30 17:36:12.450: E/AndroidRuntime(1140): FATAL EXCEPTION: main
05-30 17:36:12.450: E/AndroidRuntime(1140): Process: com.example.allinone, PID: 1140
05-30 17:36:12.450: E/AndroidRuntime(1140): java.lang.ClassCastException: android.accounts.Account cannot be cast to com.example.allinone.WebSiteObject
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.example.allinone.WebActivity.onCreateOptionsMenu(WebActivity.java:37)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:147)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:285)
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.view.Choreographer.doFrame(Choreographer.java:543)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.os.Handler.handleCallback(Handler.java:733)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.os.Looper.loop(Looper.java:136)
05-30 17:36:12.450: E/AndroidRuntime(1140): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-30 17:36:12.450: E/AndroidRuntime(1140): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 17:36:12.450: E/AndroidRuntime(1140): at java.lang.reflect.Method.invoke(Method.java:515)
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-30 17:36:12.450: E/AndroidRuntime(1140): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-30 17:36:12.450: E/AndroidRuntime(1140): at dalvik.system.NativeStart.main(Native Method)
WebActivity.java 中的第 37 行是 WebSiteObject aWebSiteObject = (WebSiteObject)getIntent().getParcelableExtra("selectedWebObject");
我在第 37 行设置了一个断点。它遇到了断点,但代码没有运行到此之外,即第 38 行永远不会执行。这里有什么问题吗?我该如何纠正这个问题?
最佳答案
两个问题..
WebSiteObject
如下
public static final Parcelable.Creator<WebSiteObject> CREATOR = new Parcelable.Creator<WebSiteObject>() {
public WebSiteObject createFromParcel(Parcel in) {
return new WebSiteObject(in);
}
public WebSiteObject[] newArray(int size) {
return new WebSiteObject[size];
}
};
2.添加构造函数
public WebSiteObject(Parcel in) {
// Read all fields in the same sequence as you have written into writeToParcel
webSiteName = in.in.readString();
webSiteURL = in.readString();
}
关于java - 使用 Intent 传递可分割对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23954300/
实际上我只需要用JAVA编写一个简单的程序来将MySQL INSERTS行转换为CSV文件(每个mysql表等于一个CSV文件) 在JAVA中使用正则表达式是最好的解决方案吗? 我的主要问题是如何正确
我有一个 txt 文件,其格式为: Key:value Key:value Key:value ... 我想将所有键及其值放入我创建的 hashMap 中。如何让 FileReader(file) 或
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果
我每周都会从我的主机下载数据库的备份。它生成一个 .sql 文件,当前大小约为 800mb。此 .sql 文件包含 44 个表。 有什么方法可以通过某些软件将 .sql 文件与所有表分开,以便单独导出
在 iOS 4.0 及更高版本中,有没有一种方法可以在不将整个图像加载到内存的情况下对 CGImage 进行分割?我试图做的是*以编程方式*分割图像,以便在使用大图像的 CATiledLayer 应用
我的 .split() 函数有问题,我有以下字符串: var imageUrl = "Images\Products\randomImage.jpg"; 我想用字符“\”分割,但是,这种情况发生了:
是否可以使用正则表达式将字符串拆分两次?例如,假设我有字符串: example=email@address.com|fname|lname 如何拆分结果为: email@address.com,fna
我正在寻找一种在线程系统(主从)中使用数组的解决方案,它允许我通过用户输入在多个线程上划分矩阵的计算,并将其通过 1 个主线程引导到多个从属线程,这些从属线程计算矩阵的 1 个字段。 我尝试运用我的知
我建立了一个系统来分割包含手写符号的二值图像并对它们进行分类(专门用于音乐)。我知道有商业应用程序可以执行此操作,但这是我尝试将其作为一个项目从头开始。 为了简单起见,假设我的整个图像中有两个元素:
我正在尝试找到一种可接受的复杂性的有效方法 检测图像中的对象,以便将其与周围环境隔离 将该对象分割成它的子部分并标记它们,这样我就可以随意获取它们 我进入图像处理世界已经 3 周了,我已经阅读了很多算
我有一组3D 空间中的点。下图是一个示例: 我想把这些点变成一个面。我只知道点的 X、Y 和 Z 值。例如,查看下图,它显示了从 3D 空间中的点生成的人脸网格。 我在谷歌上搜索了很多,但我找到的是一
我有一个字符串 String placeStr="place1*place2*place3"我想获取包含 place1、place2、place3 的数组,如下所示: String[] places=
我在 Python 中有一个类似于 google.com 的字符串,我想将其分成两部分:google 和 .com。问题是我有一个 URL,例如 subdomain.google.com,我想将其拆分
朋友需要对一个pdf文件进行分割,在网上查了查发现这个pypdf2可以完成这些操作,所以就研究了下这个库,并做一些记录。首先pypdf2是python3版本的,在之前的2版本有一个对应pypdf库。
伙计们,这是一个难以解决的问题,因为它涉及很多硬件细节,所以我想把它放到 EE.SE,但它的主要重点是编程,所以我决定坚持在这里。 我最近怀旧(以及渴望回到 CPU 内在函数),所以我决定自制一个 8
给定 haskell 中的排序列表,我如何获得分段列表,其中连续数字位于同一列表中。例如,如果我有一个排序列表 [1,2,3,4,7,8,10,12,13,15] 结果将是 [[1,2,3 ,4],[
如果我添加三个分割 View ,如下图所示,第三个分割 View (称为 splitView-3)将自动为该分割 View 中的自定义 View 生成约束,例如 customview1 的 Heigh
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
如何为馈送给映射器的文件的每一行提供相同文件的拆分? 基本上我想做的是 for each line in file-split { for each line in file{
带有Snappy压缩功能的ORC文件是否可拆分成条形? 据我所知,Snappy Compressed File是不可拆分的。 但我在博客中读到,快速压缩的文件可以在 strip 上拆分。 真的吗? 最
我是一名优秀的程序员,十分优秀!