0

当 xstream 将 ShootRecord 转换为 xml 时,为什么会出现“调用 Ljava/util/WeakHashMap 时堆栈溢出”错误?

ShootRecord 类字段和构造函数

public class ShootRecord /* implements Serializable */
{
    private String mShootRecordName = "";
    private String mShootRecordDate = "";
    private int mNumArchersOnTarget;
    private int mScoreSheetTypeIndex;

private Bitmap mScoreSheetBackground = null;

private ArrayList<ScoreSheet> mListOfScoreSheets = new ArrayList<ScoreSheet>();
private int mActiveScoreSheetIndex = 0;

private ScoreSheetsView mScoreSheetsView;

/**
 * Constructs a new ShootRecord object. 
 * @param scoreSheetsView Reference to the score sheet rendering View. 
 * @param name The name string for the shoot record. 
 * @param date The date string for the shoot record. 
 * @param archers The number of archers on the shoot record. 
 * @param sheetType The score sheet type index for the shoot record. 
 */
public ShootRecord(ScoreSheetsView scoreSheetsView, String name, String date, int archers, int sheetType)
{
    mScoreSheetsView = scoreSheetsView;

    mShootRecordName = name;
    mShootRecordDate = date;
    mNumArchersOnTarget = archers;
    mScoreSheetTypeIndex = sheetType;
}

MainActivity 类定义:

public class MainActivity extends Activity implements View.OnTouchListener

FileSender 类构造函数:

public FileSender(Activity activity)
    {
        mMainActivity = (MainActivity) activity;
    }

FileSender 中的方法:

public boolean postToServletOverWifi(ShootRecord recToSend, Context context){

try{

        /* prepare object as xml */
        XStream xstream = new XStream();

        /* make outputting of xml more concise (optional)*/
        xstream.alias("ShootRecord", ShootRecord.class);

        String xml = xstream.toXML(recToSend);  /* convert object to xml */

        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        wifiManager.startScan();
        List<ScanResult> list = wifiManager.getScanResults();
        for( ScanResult i : list ) {

            /* list network name/ssid */
            i.describeContents();
        }

            /* get user selected wifi network
            /* selectedNetwork = ??? selection from list

            if(selectedNetwork.SSID != null && selectedNetwork.SSID.equals("\"" + networkSSID + "\"")) {
                 wifiManager.disconnect();
                 wifiManager.enableNetwork(selectedNetwork.SSID, true);
                 wifiManager.reconnect();                
                 break;
            }     
            */

        /* Create WifiConfiguration instance: 
            WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + networkSSID + "\"";   // string should contain ssid in quotes
                    conf.preSharedKey = "\""+ networkPass +"\"";
                    wifiManager.addNetwork(conf);


        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://" + server + "/Archery");
        post.setHeader("Content-type", "text/xml;charset=utf-8");



some call to post xml?? 
*/

} catch (Exception e){
             System.out.println( e.getMessage() );
             e.printStackTrace();
             return false;

}

} //end method 

调用方法:

public void promptUserToSendShootRecord(ShootRecord recToSend) {

    final ShootRecord shootRecord = recToSend;

    createIntentToSendZippedRecord(shootRecord); //this method works
    postToServletOverWifi(shootRecord, mMainActivity.mContext);
}

目录

4

1 回答 1

0

看来我的问题类似于在 init 之外的 java 中创建对象,我可能在这里发生递归调用,但不确定在哪里/为什么

于 2013-07-20T11:26:00.983 回答