java.lang.IllegalStateException: Can’t change tag of fragment PageFragment{42ef29a8 #14 id=0x7f060052 android:switcher:2131099730:22}: was android:switcher:2131099730:22 now android:switcher:2131099730:17
后面在SUN的官方论坛上看到有人提到这个问题“works on windows, don’t work on linux”,后面有人回复说是“file systems”不一样。究竟怎么不一样呢?还是没有想出来…
后面在一个论坛里面发现了某人关于这个问题的阐述:
In the Unix’esque O/S’s you cannot renameTo() across file systems. This behavior is different than the Unix “mv” command. When crossing file systems mv does a copy and delete which is what you’ll have to do if this is the case.
The same thing would happen on Windows if you tried to renameTo a different drive, i.e. C: -> D:
终于明白咯。
做个实验:
1 2 3 4 5 6 7 8 9 10 11 12 13
File sourceFile = new File("c:/test.txt"); File targetFile1 = new File("e:/test.txt"); File targetFile2 = new File("d:/test.txt"); System.out.println("source file is exist? " + sourceFile.exists() + ", source file => " + sourceFile); System.out.println(targetFile1 + " is exist? " + targetFile1.exists()); System.out.println("rename to " + targetFile1 + " => " + sourceFile.renameTo(targetFile1)); System.out.println("source file is exist? " + sourceFile.exists() + ", source file => " + sourceFile); System.out.println(targetFile2 + " is exist? " + targetFile2.exists()); System.out.println("rename to " + targetFile2 + " => " + sourceFile.renameTo(targetFile2));
结果:
source file is exist? true, source file => c:\test.txt
e:\test.txt is exist? false
rename to e:\test.txt => false
source file is exist? true, source file => c:\test.txt
d:\test.txt is exist? false
rename to d:\test.txt => true
public interface Parcelable { //内容描述接口,基本不用管 public int describeContents(); //写入接口函数,打包 public void writeToParcel(Parcel dest, int flags); //读取接口,目的是要从Parcel中构造一个实现了Parcelable的类的实例处理。 //因为实现类在这里还是不可知的,所以需要用到模板的方式,继承类名通过模板参数传入。 //为了能够实现模板参数的传入,这里定义Creator嵌入接口,内含两个接口函数分别返回单个和多个继承类实例。 public interface Creator<T> { public T createFromParcel(Parcel source); public T[] newArray(int size); } }
在实现Parcelable的实现中,规定了必须定义一个静态成员, 初始化为嵌入接口的实现类。
1 2
publicstatic Parcel.Creator<DrievedClassName> CREATOR = new Parcel.Creator<DrievedClassName>();