这种事情都会发生?奇迹啊。。高分悬赏...

visoeclipse 2009-12-01 07:10:00
public void locationUpdated(LocationProvider lp , final Location location)
{
if(location.isValid())
{
Coordinates coordinates = location.getQualifiedCoordinates() ;
if(coordinates != null)
{
double latitude = coordinates.getLatitude() ;
double longitude = coordinates.getLongitude() ;
try
{
rmso.save(latitudeString+longitudeString) ;
}
catch(Exception e)
{
rmso.deleteRecordStore() ;
e.printStackTrace();
}
}
}
}


RMS封装类:

public void save(String info) throws RecordStoreFullException , RecordStoreNotFoundException , RecordStoreException
{
if(recordStore == null)
{
recordStore = RecordStore.openRecordStore(this.storeName , true) ;
}
byte[] byt = info.getBytes() ;
int recordNum = recordStore.getNumRecords() ;
if(recordNum == 0)
{
recordStore.addRecord(byt , 0 , byt.length) ;
}
else
{
recordStore.setRecord(1 , byt , 0 , byt.length) ;
}
recordStore.closeRecordStore() ;
}


问题: 为什么我在 locationUpdated 方法中调用 rms 封装类的save方法,我的nokia5800就只执行一次而如果我注释掉save方法的调用它就能正常执行呢?

rms 不是线程安全的吗。 何况也就这一个 类线程 在调用啊。 哪位仁兄帮帮忙看看。...
...全文
216 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
踏雪耗子 2009-12-02
  • 打赏
  • 举报
回复
学习~
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
无论我在那里调用,只要顺次或则在在同一个主线程里面出现了这两个:rms 和 locationupdate ,它就会出现这样的情况,何况jsr179是nokia 创造出来的。 为什么还会出现这样的情况在nokia上面
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
恩咯
kf156 2009-12-02
  • 打赏
  • 举报
回复
我是指你18L贴出的代码里的Test()方法。
也是在startApp()里调吗?
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
外面。startapp 里面。
kf156 2009-12-02
  • 打赏
  • 举报
回复
你Test()方法在哪执行?
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
我想。 难道这世界上都没人遇见过类似的???.???????
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
这个类的代码如下:

public class Locationor extends Canvas implements CommandListener , LocationListener
{

private Realtime realtime ;

private final String latitudeString = "Latitude: " ;
private final String longitudeString = "Longitude: " ;
private final String times = "time: " ;
private final String error = "error: " ;
private final int index = 0 ;

private final Font font ;
private final Command exitCommand = new Command("exit" , Command.EXIT , 1) ;
private final RMSOperator rmso = new RMSOperator("test") ;

public void setRealtime(Realtime realtime)
{
this.realtime = realtime ;
}

public Locationor()
{
this.addCommand(exitCommand) ;
this.setCommandListener(this) ;
font = Font.getFont(Font.FACE_SYSTEM , Font.STYLE_PLAIN , Font.SIZE_SMALL) ;

Criteria criteria = new Criteria() ;
try
{
LocationProvider locationProvider = LocationProvider.getInstance(criteria) ;
if(locationProvider != null)
{
locationProvider.setLocationListener(this , - 1 , - 1 , - 1) ;
}
}
catch(LocationException e)
{
e.printStackTrace() ;
}
}

public static void Test()
{
try
{
RecordStore recordStore = RecordStore.openRecordStore("rickytest123", true) ;
// recordStore.closeRecordStore() ;
}
catch(RecordStoreFullException e)
{
e.printStackTrace();
}
catch(RecordStoreNotFoundException e)
{
e.printStackTrace();
}
catch(RecordStoreException e)
{
e.printStackTrace();
}
}

protected void paint(Graphics g)
{
g.setColor(255 , 255 , 255) ;
g.fillRect(0 , 0 , getWidth() , getHeight()) ;
g.setColor(0 , 0 , 0) ;
g.setFont(font) ;
int height = font.getHeight() ;
g.drawString(latitudeString , 0 , 0 , Graphics.TOP | Graphics.LEFT) ;
g.drawString(longitudeString , 0 , height , Graphics.TOP | Graphics.LEFT) ;
g.drawString(times , 0 , 2 * height , Graphics.TOP | Graphics.LEFT) ;
g.drawString(error , 0 , 3 * height , Graphics.TOP | Graphics.LEFT) ;

}

public void locationUpdated(LocationProvider lp , final Location location)
{
if(location.isValid())
{
Coordinates coordinates = location.getQualifiedCoordinates() ;
if(coordinates != null)
{
double latitude = coordinates.getLatitude() ;
double longitude = coordinates.getLongitude() ;
long time = location.getTimestamp() ;
//times = "time : " + String.valueOf(time) ;
//latitudeString = "Latitude: " + latitude ;
//longitudeString = "Longitude: " + longitude ;

Track track = new Track();
track.setCreateDate(time);
track.setLatitude(latitude);
track.setLongitude(longitude);


if(null!=System.getProperty("microedition.io.file.FileConnection.version"))
{
JSR75FileStore fileStore = new JSR75FileStore();
fileStore.saveData(track);
}
repaint() ;
}
}
}

public void providerStateChanged(LocationProvider arg0 , int arg1)
{}
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 kf156 的回复:]
locationUpdated方法里
rmso.save(latitudeString+longitudeString) ; //参数的字符串哪来的?

估计还是你代码的问题,最好带上完整点的代码
[/Quote]

奥。 忘记了,把它转换成string了,后面删除了,为了查出问题 不影响流程的东西都干掉了
hejunlong007 2009-12-02
  • 打赏
  • 举报
回复
kf156 2009-12-02
  • 打赏
  • 举报
回复
locationUpdated方法里
rmso.save(latitudeString+longitudeString) ; //参数的字符串哪来的?

估计还是你代码的问题,最好带上完整点的代码
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
单独运行 rms 或则 location 都是没有问题的. 天啦,谁救救我吧
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
错了。
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
protected void startApp() throws MIDletStateChangeException
{

try
{
RecordStore recordStore = RecordStore.openRecordStore("rickytest123", true) ;
}
catch(RecordStoreFullException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(RecordStoreNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
display = Display.getDisplay(this) ;

Thread thread = new Thread()
{
public void run()
{
i++ ;
Alert alert = new Alert("Alert" , i , null , AlertType.INFO) ;
MobileTracker.this.display.setCurrent(alert) ;

}
};
thread.start();
try
{
thread.sleep(100);
}
catch(InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

就弹出一次。 难道
kf156 2009-12-02
  • 打赏
  • 举报
回复
你另外单独写个程序,只调用相关的RMS操作,看看会不会有类似问题。
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
你说的我试过, 还是没有, 无论怎样,即是我在外部调用那个 测试的 static 方法时, 它都会终止掉。 很是纳闷
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
就是gps模块不运行了, 无法执行 回调的 locationListener 了。 相当于程序终止了。
kf156 2009-12-02
  • 打赏
  • 举报
回复
在手机上把程序删了,再重新装过。

再加多个catch(Exception e)

然后再试看看有没什么问题。
还有挂掉是指什么现象?
visoeclipse 2009-12-02
  • 打赏
  • 举报
回复
谢谢你们, 但是即是像你们说的那样, 如果你在实现了 locationlistener 接口的方法中创建任何一个rms实例的话,你只要让它运行一次,你看咯,整个程序时不可能执行下去的。昨天我一个个排除,除非在 实现 locationListener 类里面不用到 rms , 否则无论怎么写,它还是无法正常执行的。
我用的真机是自己的 nokia 5800 . 不知道是 nokia 的问题还是 什么问题。

代码:
public static void Test()
{
try
{
RecordStore recordStore = RecordStore.openRecordStore("rickytest123", true) ;
// recordStore.closeRecordStore() ;
}
catch(RecordStoreFullException e)
{
e.printStackTrace();
}
catch(RecordStoreNotFoundException e)
{
e.printStackTrace();
}
catch(RecordStoreException e)
{
e.printStackTrace();
}
}


我只要在 主线程或则其他任何可以运行的地方调用这个方法,它就立刻挂掉。

真的很郁闷 ........
softice_ 2009-12-01
  • 打赏
  • 举报
回复
这样设计不算太合理,应该在程序开始时打开rms,程序结束时关闭rms
加载更多回复(4)

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧