- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 2 个 fragment 的 Fragment Activity ,该 fragment Activity 将我的类的数组列表传递给它的 2 个 fragment 。
这 2 个 fragment 在启动时成功接收到了 Parcellable 数组列表,但是当我旋转我的应用程序时,弹出了 Parcelable:Class not found when unmarshalling 错误,我真的不知道出了什么问题。请帮我。抱歉英语不好。
这是我的 FragmentActivity 的代码
public class Activity_Viewdata extends FragmentActivity implements selector {
private static final String TAG = Activity_Viewdata.class.getSimpleName();
private static ArrayList<sentdata> sneardatalist = new ArrayList<sentdata>();
private ViewGroup mapLayout, listLayout;
public static FragmentManager fragmentManager;
Fragment_listview fragment_list;
Fragment_map fragment_map;
FragmentManager myFragmentManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitivity_view_pdata);
Log.i(TAG, "here in viewdata");
Bundle mBundle = getIntent().getExtras();
sneardatalist= mBundle.getParcelableArrayList("myList"); //getIntent().getParcelableExtra("myList");
Log.i(TAG, "Size is: " + sneardatalist.size());
Log.v(TAG, "onCreate: savedInstanceState " + (savedInstanceState == null ? "==" : "!=") + " null");
fragmentManager = getSupportFragmentManager();
if(savedInstanceState !=null){
savedInstanceState.getParcelableArrayList("myList");
}else{
mapLayout = (ViewGroup) findViewById(R.id.frameLayout_map);
if(mapLayout!=null){
Log.i(TAG, "onCreate: adding mapview to MainActivity");
Fragment_map fragmentmap = Fragment_map.newInstance(sneardatalist);
FragmentTransaction fragmenttransaction = getSupportFragmentManager().beginTransaction();
fragmenttransaction.replace(mapLayout.getId(), fragmentmap, Fragment_map.class.getName());
fragmenttransaction.commit();
}
listLayout = (ViewGroup) findViewById(R.id.frameLayout_pager);
if(listLayout!=null){
Log.i(TAG, "onCreate: adding listview to MainActivity");
Fragment_listview fragmentlst = Fragment_listview.newInstance(sneardatalist);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(listLayout.getId(), fragmentlst, Fragment_listview.class.getName());
fragmentTransaction.commit();
}
}
}
这是第一个 fragment
public class Fragment_listview extends Fragment implements OnPageChangeListener{
private static final String TAG = Fragment_listview.class.getSimpleName();
private static final String MYLIST = "myList";
private static ArrayList<sentdata> data = new ArrayList<sentdata>();
private selector selectorListener;
private Boolean mInitialCreate=true;
ViewPager viewPager;
PagerAdapter adapter;
public static Fragment_listview newInstance(ArrayList<sentdata> _data){
Log.i(TAG, "List Size:" + _data.size());
Fragment_listview newfragment_listview = new Fragment_listview();
Bundle args = newfragment_listview.getArguments();
if(args==null){
args = new Bundle();
}
args.putParcelableArrayList(MYLIST, _data);
newfragment_listview.setArguments(args);
return newfragment_listview;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Fragment parentFragment = getParentFragment();
if (parentFragment != null && parentFragment instanceof selector) {
selectorListener = (selector) parentFragment;
}
else if (activity != null && activity instanceof selector) {
selectorListener = (selector) activity;
}
else if (selectorListener == null) {
Log.w(TAG, "onAttach: niether the parent fragment or parent activity implement OnImageSelectedListener, "
+ "image selections will not be communicated to other components");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.w(TAG, "here in OCREATE Of list");
Bundle args = getArguments();
if (args != null) {
data = args.getParcelableArrayList(MYLIST);
}
if (savedInstanceState != null) {
data = savedInstanceState.getParcelableArrayList(MYLIST);
mInitialCreate = false;
}
else {
mInitialCreate = true;
}
Log.w(TAG, "here in OCREATE Of map" + "Size is " + data.size());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.v(TAG, "onCreateView: savedInstanceState " + (savedInstanceState == null ? "==" : "!=") + " null");
View v = inflater.inflate(R.layout.fragment_list, container, false);
viewPager = (ViewPager) v.findViewById(R.id.pager);
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
public void onPageSelected(int position) {
// Check if this is the page you want.
Log.d(TAG, "onPageSelected: " + position);
if (selectorListener != null) {
selectorListener.setdata(Double.parseDouble(data.get(position).getlat()), Double.parseDouble(data.get(position).getlong()), position,2);
}
}
});
Log.i(TAG, "here in listview: " + data.size() );
if(mInitialCreate && data.size()!=0){
adapter = new viewpager_adapter(getActivity(),data);
viewPager.setAdapter(adapter);
}
if (mInitialCreate) {
mInitialCreate = false;
}
return v;
}
@Override
public void onSaveInstanceState(Bundle outState) {
Log.w(TAG, "onSaveInstanceState" + "Saving list");
outState.putParcelableArrayList(MYLIST, data);
super.onSaveInstanceState(outState);
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
这是我的 Fragment2
public class Fragment_map extends Fragment{
private static final String TAG = Fragment_map.class.getSimpleName();
private static final String MYLIST = "myList";
List<Marker> markers = new ArrayList<Marker>();
MapView mMapView;
private GoogleMap googleMap;
private selector selectorListener;
private static ArrayList<sentdata> data = new ArrayList<sentdata>();
private Boolean mInitialCreate=true;
public static Fragment_map newInstance(ArrayList<sentdata> _data){
Log.i(TAG, "List Size:" + _data.size());
Fragment_map newfragment_map = new Fragment_map();
Bundle args = newfragment_map.getArguments();
if(args==null){
args = new Bundle();
}
args.putParcelableArrayList(MYLIST, _data);
newfragment_map.setArguments(args);
return newfragment_map;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Fragment parentFragment = getParentFragment();
if (parentFragment != null && parentFragment instanceof selector) {
selectorListener = (selector) parentFragment;
}
else if (activity != null && activity instanceof selector) {
selectorListener = (selector) activity;
}
else if (selectorListener == null) {
Log.w(TAG, "onAttach: niether the parent fragment or parent activity implement OnImageSelectedListener, "
+ "image selections will not be communicated to other components");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.w(TAG, "here in OCREATE Of map");
Bundle args = getArguments();
if (args != null) {
data = args.getParcelableArrayList(MYLIST);
}
if (savedInstanceState != null) {
data = savedInstanceState.getParcelableArrayList(MYLIST);
mInitialCreate = false;
}else {
mInitialCreate = true;
}
Log.w(TAG, "here in OCREATE Of map" + "Size is " + data.size());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
mMapView = (MapView) rootView.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();// needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
googleMap = mMapView.getMap();
googleMap.setOnMarkerClickListener(new OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(Marker arg0) {
for(int i=0; i< markers.size();i++){
if(arg0.equals(markers.get(i))){ // if marker source is clicked
Log.w(TAG,"Clicked");
selectorListener.setlist(i);
}
// display toast;
}
return true;
}
});
if(mInitialCreate && data.size()!=0){
setmap();
}
if (mInitialCreate) {
mInitialCreate = false;
}
return rootView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
Log.w(TAG, "onSaveInstanceState" + "Saving list");
outState.putParcelableArrayList(MYLIST, data);
super.onSaveInstanceState(outState);
}
public void setmap(){
........
}
public void setview(double lat, double longt, int num){
......
}
这是我的课
public class sentdata implements Parcelable{
private int _id;
private String _data="";
private String _lat="";
private String _long="";
private String _img="";
private String _imgP="";
private int _sntvia;
private String _snttime="";
private String _template="";
public sentdata(){}
public sentdata( String data, String lat, String longt, String img, String imgp, int sntvia, String sntime, String template ){
this._data = data;
this._lat = lat;
this._long = longt;
this._img = img;
this._imgP = imgp;
this._sntvia = sntvia;
this._snttime = sntime;
this._template = template;
}
public sentdata( int id, String data, String lat, String longt, String img, String imgp, int sntvia, String sntime, String template ){
this._id = id;
this._data = data;
this._lat = lat;
this._long = longt;
this._img = img;
this._imgP = imgp;
this._sntvia = sntvia;
this._snttime = sntime;
this._template = template;
}
public int getid(){
return this._id;
}
public void setid(int id){
this._id = id;
}
public void setdata(String data){
this._data = data;
}
public String getdata(){
return this._data;
}
public void setlat(String lat){
this._lat = lat;
}
public String getlat(){
return this._lat;
}
public void setlong(String longt){
this._long = longt;
}
public String getlong(){
return this._long;
}
public void setimg(String img){
this._img = img;
}
public String getimg(){
return this._img;
}
public void setimgP (String imgP){
this._imgP = imgP;
}
public String getimgP(){
return this._imgP;
}
public void setsentvia(int sntvia){
this._sntvia = sntvia;
}
public int getsentvia(){
return this._sntvia;
}
public void setsentTime(String sentime ){
this._snttime = sentime;
}
public String getsenttime(){
return this._snttime;
}
public void settemp (String tmp ){
this._template = tmp;
}
public String gettmp(){
return this._template;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public sentdata(Parcel source){
_id = source.readInt();
_data = source.readString();
_lat = source.readString();
_long = source.readString();
_img = source.readString();
_imgP = source.readString();
_sntvia = source.readInt();
_snttime = source.readString();
_template = source.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeInt(_id);
dest.writeString(_data);
dest.writeString(_lat);
dest.writeString(_long);
dest.writeString(_img);
dest.writeString(_imgP);
dest.writeInt(_sntvia);
dest.writeString(_snttime);
dest.writeString(_template);
}
public static final Parcelable.Creator<sentdata> CREATOR = new Parcelable.Creator<sentdata>() {
@Override
public sentdata createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new sentdata(source);
}
@Override
public sentdata[] newArray(int size) {
// TODO Auto-generated method stub
return new sentdata[size];
}
};
我是android新手,可能有一些我需要知道的事情,所以请帮忙。我一直在谷歌上寻找解决方案。谢谢。
这是我的 LogCat
05-07 14:25:03.093: V/Fragment_map(17606): onDestroyView
05-07 14:25:03.153: V/Fragment_listview(17606): onDestroyView
05-07 14:25:03.173: V/Fragment_listview(17606): onDestroy
05-07 14:25:03.173: V/Activity_Viewdata(17606): onDestroy
05-07 14:25:03.213: W/Fragment_listview(17606): here in OCREATE Of list
05-07 14:25:03.213: W/Fragment_listview(17606): here in OCREATE Of mapSize is 2
05-07 14:25:03.263: I/Activity_Viewdata(17606): here in viewdata
05-07 14:25:03.273: I/Activity_Viewdata(17606): Size is: 2
05-07 14:25:03.273: V/Activity_Viewdata(17606): onCreate: savedInstanceState != null
05-07 14:25:03.273: I/Google Maps Android API(17606): Google Play services package version: 7329032
05-07 14:25:03.383: E/Parcel(17606): Class not found when unmarshalling: com.ictcsu.DatabaseClasses.sentdata, e: java.lang.ClassNotFoundException: com.ictcsu.DatabaseClasses.sentdata
05-07 14:25:03.383: D/AndroidRuntime(17606): Shutting down VM
05-07 14:25:03.383: W/dalvikvm(17606): threadid=1: thread exiting with uncaught exception (group=0x40fe72a0)
05-07 14:25:03.403: E/AndroidRuntime(17606): FATAL EXCEPTION: main
05-07 14:25:03.403: E/AndroidRuntime(17606): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ictcsu.testapp1/com.ictcsu.viewdata.Activity_Viewdata}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.ictcsu.DatabaseClasses.sentdata
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3568)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread.access$700(ActivityThread.java:134)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.os.Looper.loop(Looper.java:137)
05-07 14:25:03.403: E/AndroidRuntime(17606): at android.app.ActivityThread.main(ActivityThread.java:4830)
05-07 14:25:03.403: E/AndroidRuntime(17606): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 14:25:03.403: E/AndroidRuntime(17606): at java.lang.reflect.Method.invoke(Method.java:511)
05-07 14:25:03.403: E/AndroidRuntime(17606): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
最佳答案
当你旋转屏幕时,android 会销毁 Activity 并重新创建它,这就是你的包返回 null 的原因。尝试将其存储在 onSaveInstanceState 并在 oncreate 方法中检索它。
公共(public)类 Activity_Viewdata 扩展 FragmentActivity 实现选择器 {私有(private)静态最终字符串TAG = Activity_Viewdata.class.getSimpleName();私有(private)静态ArrayList sneardatalist = new ArrayList();私有(private)ViewGroup mapLayout,listLayout;公共(public)静态FragmentManagerfragmentManager;
fragment_list View fragment_list; fragment _映射 fragment _映射;FragmentManager myFragmentManager;
@覆盖protected void onCreate(Bundle savingInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.acitivity_view_pdata);
Log.i(TAG, "here in viewdata");
Bundle mBundle = getIntent().getExtras();
sneardatalist= mBundle.getParcelableArrayList("myList"); //getIntent().getParcelableExtra("myList");
Log.i(TAG, "Size is: " + sneardatalist.size());
Log.v(TAG, "onCreate: savedInstanceState " + (savedInstanceState == null ? "==" : "!=") + " null");
fragmentManager = getSupportFragmentManager();
if(savedInstanceState !=null){
// **remove it you are doing it in fragment right ??**
// savedInstanceState.getParcelableArrayList("myList");
}else{
mapLayout = (ViewGroup) findViewById(R.id.frameLayout_map);
if(mapLayout!=null){
Log.i(TAG, "onCreate: adding mapview to MainActivity");
Fragment_map fragmentmap = Fragment_map.newInstance(sneardatalist);
FragmentTransaction fragmenttransaction = getSupportFragmentManager().beginTransaction();
fragmenttransaction.replace(mapLayout.getId(), fragmentmap, Fragment_map.class.getName());
fragmenttransaction.commit();
}
listLayout = (ViewGroup) findViewById(R.id.frameLayout_pager);
if(listLayout!=null){
Log.i(TAG, "onCreate: adding listview to MainActivity");
Fragment_listview fragmentlst = Fragment_listview.newInstance(sneardatalist);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(listLayout.getId(), fragmentlst, Fragment_listview.class.getName());
fragmentTransaction.commit();
}
}
}
你的 fragment 尝试保存数组列表的实例状态并尝试在创建的 Activity 上检索它
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if(savedInstanceState!=null){
sneardatalist=savedInstanceState.getParcelableArrayList("myList");
}
}
关于java - Parcelable:在 fragment 旋转时解码错误时未找到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30091871/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!