【问题标题】:Invalid heap address and fatal signal 11 while decoding json string into java object将json字符串解码为java对象时堆地址无效和致命信号11
【发布时间】: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


    【解决方案1】:

    this 看来,您的 libc 堆已损坏;您是否已加载并运行任何本机库?

    【讨论】:

      【解决方案2】:

      我使用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"));
      

      【讨论】:

        猜你喜欢
        • 2012-05-26
        • 2020-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-08
        • 1970-01-01
        • 2016-09-25
        相关资源
        最近更新 更多