2014-04-09 13 views
0

我從另一個類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和借鑑他們在畫布上。

回答

0

this它看起來像你的libc堆已損壞;你有任何本地庫加載和運行?

0

我注意到這個問題使用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")); 
相關問題