我從另一個類useActivity多次調用類DrawingView的靜態方法updateHistory(String message)。 updateHistory法(內標代碼段)內的語句創建運行時異常的將json字符串解碼爲java對象時無效的堆地址和致命信號11
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.fromJs每次調用該方法時都會創建新的ArrayList對象。
注意
我的基本目標是將JSON字符串(以前從路徑ArrayList的編碼)轉換爲路徑的ArrayList和借鑑他們在畫布上。