[英]Invalid heap address and fatal signal 11 while decoding json string into java object
我多次從另一個類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字符串(以前是從Path的ArrayList編碼)轉換為Paths的ArrayList並將它們繪制在畫布上。
從這個它看起來像你的libc堆損壞; 您是否已加載並運行任何本機庫?
我已經注意到使用fromJson
方法的問題。 為避免此錯誤,請將這部分代碼更改為如下所示:
JSONObject json = new JSONObject(str);
Location objLocation = new Location("");
objLocation.setLatitude(json.getDouble("mLatitude"));
objLocation.setLongitude(json.getDouble("mLongitude"));
objLocation.setTime(json.getLong("mTime"));
objLocation.setAccuracy( (float)
json.getDouble("mAccuracy"));
objLocation.setAltitude( json.getDouble("mAltitude"));
objLocation.setBearing( (float) json.getDouble("mBearing"));
objLocation.setElapsedRealtimeNanos( json.getLong("mElapsedRealtimeNanos"));
objLocation.setSpeed( (float) json.getDouble("mSpeed"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.