【发布时间】:2014-04-09 16:48:04
【问题描述】:
我多次从另一个类 useActivity 调用类 DrawingView 的静态方法 updateHistory(String message)。 updateHistory 方法中的语句(标记在代码部分)创建运行时异常为
A/libc(8006): @@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x6552d4a8
A/libc(8006): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 8015 (FinalizerDaemon)
useActivity.java
public class UseActivity extends Activity implements Observer {
public void onCreate(Bundle savedInstanceState){...}
...
public void updateHistory{
...
for loop(10 times){
DrawingView.updateHistory(message); //called 10 times & message is a string changes every time
}
...
...
}//class ends
DrawingView.java
public class DrawingView extends View implements OnTouchListener {
public static DrawingView my_View=null;
public DrawingView(Context context, AttributeSet attr) {
super(context);
my_View=this;
...
}
public static void updateHistory(String json){
Gson gson2=new Gson();
ArrayList<Pair<Path, Paint>> my_Paths=gson2.fromJson(json,new TypeToken<ArrayList<Pair<Path,Paint>>>(){}.getType());
//The above statement creates problem
...
}
}//class ends
我如何更改该语句,因为 gson2.fromJson 每次调用该方法时都会创建新的 arraylist 对象。
注意
我的基本目标是将 json 字符串(之前从路径的 ArrayList 编码)转换为路径的 ArrayList 并将它们绘制在画布上。
【问题讨论】:
标签: java android json arraylist static