Storing values for object instances between runs
I'm writing a simple 2d game and I'm trying to create an object to handle the information about individual tiles on the board.
The tile class will handle three pieces of information:
1. an image to represent the tile
2. a boolean value (true if the tile can be passed through, false if it blocks movement)
3. a name to describe the surface (mostly for management purposes - so I can say load("whiteMarble01") instead of using the full directory.)
I plan to pre-build instances of these so that the tiles can be quickly placed with all their options pre-assigned.
How would you store this data between runs of the game?
My first thought was a folder (named whatever the name should be) containing an image file and a text file (which contains all the remaining values to be parsed). I don't think this is very good since the text file would only serve to store the boolean.
Is there a better way?
You can also use any of the standard XML APIs or java.beans classes XMLEndcoder and XMLDecoder:
import java.beans.*;
import java.io.*;
import java.util.*;
public class ExampleBean {
private String name;
private int code;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setCode(int code) {
this.code = code;
public int getCode() {
return code;
public ExampleBean() {
public ExampleBean(String name, int code) {
setName(name);
setCode(code);
@Override public String toString() {
return "(" + getName() + ", " + getCode() + ")";
public static void main(String[] args) throws IOException {
List<ExampleBean> beans = new ArrayList<ExampleBean>();
beans.add(new ExampleBean("Homer", 40));
beans.add(new ExampleBean("Marge", 37));
File file = new File("temp.xml");
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(file)));
e.writeObject(beans);
e.close();
XMLDecoder d = new XMLDecoder(
new BufferedInputStream(
new FileInputStream(file)));
System.out.println(d.readObject());
d.close();
}temp.xml:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0" class="java.beans.XMLDecoder">
<object class="java.util.ArrayList">
<void method="add">
<object class="ExampleBean">
<void property="code">
<int>40</int>
</void>
<void property="name">
<string>Homer</string>
</void>
</object>
</void>
<void method="add">
<object class="ExampleBean">
<void property="code">
<int>37</int>
</void>
<void property="name">
<string>Marge</string>
</void>
</object>
</void>
</object>
</java>
Similar Messages
-
Share Java Object Instance between JSP's
Hi@all!
Can i share a Java Object Instance between JSPages?
Example:
Class x
Public Attribute txt
Object creation in x.jsp
set public Attribute txt to "HelloWorld"
goto y.jsp
get value from txt
or...
a global package
thnx for helpHere is a tutorial that explains how to use jsps and javabeans together.
http://www.roseindia.net/jsp/usingbeansinjsp.shtml
Quick question is sounds like you are pretty early in your development phase. Have you considered adopting JSF. You may find it a bit easier.
Regards. -
I am trying to install TFS 2012 update 4 on single server installation.
I am getting below error:
TF400525: Make sure the SQL Server Reporting Services service for this instance is running.Hi CFSA,
Thanks for your post.
If you want install TFS 2012 Server with Reporting Server, you must ensure the provided Reporting Services is running first.
As Daniel said, please check that in SQL Server Configuration Manager to ensure Reporting Services is installed and running.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
For Grant nnnnnn, specify a value for object FUND error -Urgent
I work in SRM area and my knowledge of Grants management is almost nil. We have a PO in SRM which has account assignment associated with a Workorder and Fund. When we look at the Grant it has all green lights and is confirmed by our FI/CO team everything is correct. But since R/3 is giving this message "For Grant nnnnnn, specify a value for object FUND" , I am sure there is something missing somewhere. Some additional information, the PO is from last fiscal year but it was changed for account assignment this fiscal year. But we checked the Fund itself is valid for some more time to come.
Any ideas on which transaction codes to see, what to look at etc. will be appreciated.
ThanksHi Manjula,
You have been facing this issue becuase the sequence of the fields while mapping them is not perfect, hence the 0date field is capturing some other data rather than picking the exact date value.
Check the order of fields and match it with the file (if you are loading data from a flat file)
Also, have a look at the weblog which talks about general mistakes in loading from file.
/people/sergio.locatelli2/blog/2006/11/02/upload-file-in-bw-common-mistakes-and-hints-to-take-in-mind
Cheers!
Amit -
V$parameter view - How do I get these values for both instances on the db?
I have a procedure that dumps the contents of all the parameters from the system view v$parameter for auditing purposes, so that we know if a parameter changed from month to month, but we have 2 instances running. How do I make sure and log the parameters for both the instances? So far the procedure will log the parameters for the instance it happened to run on (it is random).
However, when I use TOAD, I can access parameters for both instances by going to Database/Administer/Oracle Parameters.
Thanks!Instead of V$PARAMETER use GV$PARAMETER so you can obtain the the instance id
SQL> describe gv$parameter
Name Null? Type
INST_ID NUMBER
NUM NUMBER
NAME VARCHAR2(80)
TYPE NUMBER
VALUE VARCHAR2(4000)
DISPLAY_VALUE VARCHAR2(4000)
ISDEFAULT VARCHAR2(9)
ISSES_MODIFIABLE VARCHAR2(5)
ISSYS_MODIFIABLE VARCHAR2(9)
ISINSTANCE_MODIFIABLE VARCHAR2(5)
ISMODIFIED VARCHAR2(10)
ISADJUSTED VARCHAR2(5)
ISDEPRECATED VARCHAR2(5)
ISBASIC VARCHAR2(5)
DESCRIPTION VARCHAR2(255)
UPDATE_COMMENT VARCHAR2(255)
HASH NUMBER
SQL> -
How to communicate (transfer object instance) between to java vm?
Hello, All
If possible to transfer object instance straight between two java vm?It is possible to copy an object instance from one java application to another. Define it as serializable, and pass it as a parameter to an RMI call.
-
How to find out import & export path for object migration between D Q & P?
Hi guys!
Is there a way, how to find out export and import path for object transport on XI?
Thanx!
OlianHi,
Have a look at these links.
When we do an export of the IR or the ID Oblects, a typical path at which it gets exported in the XI Server is as follow:
For IR Objects:
C:\usr\sap\PI1\SYS\global\xi\repository_server\export
For ID Objects:
"C:\usr\sap\PI1\SYS\global\xi\directory_server\export"
Now in case you need to import the ".tpz" that you have.... You need to place it in the path mentioned below and u will be able to do import it from IR or ID...
For IR Objects:
C:\usr\sap\PI1\SYS\global\xi\repository_server\import
For ID Objects:
"C:\usr\sap\PI1\SYS\global\xi\directory_server\import"
File Level transport in sap xi
Every SLD related transport details are explained here
Regarding transport of SLD objects
https://service.sap.com/~sapdownload/011000358700001684302005E/HowToSLDandXI.pdf
Regarding transport of XI objects
http://help.sap.com/saphelp_nw04/helpdata/en/93/a3a74046033913e10000000a155106/content.htm
Regards,
Akshay Jamgaonkar.
Reward points if find useful.
Message was edited by:
Akshay Jamgaonkar
Message was edited by:
Akshay Jamgaonkar -
Error for object oriented alv running in background.
Hi all,
I have an ALV report done using object oriented functionality.
When I am trying to run that report in background , it is giving me error.
I want to know why it is happening and how it can be corrected.
Regards,
Vaibhav.Create a docky container :
c_docking_cont TYPE REF TO cl_gui_docking_container.
*For background execution
IF sy-batch EQ c_x.
CREATE OBJECT c_alv
EXPORTING
i_parent = c_docking_cont.
ENDIF.
ALV for display field details
CALL METHOD c_alv->set_table_for_first_display
EXPORTING
is_layout = t_lay
CHANGING
it_outtab = t_table[]
it_fieldcatalog = t_field_cat.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Edited by: Madhavi t on Nov 2, 2009 1:34 PM -
Different Value for Object Currency and CO Currency
Hi,
We have ran a full settlement for an Internal Order again a Fixed Asset
but the problem is that the Value CO Currency Field is
displaying a different amount to that of Value Object Currency and the
currency code for both fields is the same which is ZAR currency.
Please advise,
Thanks,
Themba SindaneCheck if any value date is entered in Budget profile. Currency translation happens with Exc rate available at value date for controlling area currency.
Hope this helps -
Dear Gurus,
I'm in mid of creating transformation for my time dimension.
I'm not sure what is the value stored in 0FISCPER. Currently i'm having incoming value as Calendar year month (06.2009). The fiscal year is from Feb to JAn What is the format of data stored in this infoobject? What is the use of this infoobject ?
Thank you
BRHi
The 0FISCPER will contain the posting period followed by fiscal year.and its format will be PPP.YYYY.
Like in your case for Calendar year month (06.2009) 0FISCPER will be 005.2010 (If your Fiscal year 2010 is starting from cal year feb 2009).
But this fiscal period will be dependent on def of fiscal variant.You can get this as per your system configuration by executing the Function module DATE_TO_PERIOD_CONVERT.Enter the cal day and Fiscal year variant for which you require your 0FISCPER.
On executing this you will get the posting period as ppp and year as YYYY.which on concatenating will give you 0FISCPER as ppp.yyyy.
Hope this answers you.
-Vikram -
How to set dynamic value for field Month when running background job ?
Dear guys,
I have a Z* report in our company, in the selection screen there is a period field (Month and Year) and this report running in background job periodically. My Question is how i can set for Month field become dynamic follow month value of date when this report executed ?
Example :
When Z* report running in background on 16.04.2008, Month Value will be 04 and when running on 16.05.2008, Month Value will be 05.
Please advice.
Regards
GunawanDear guys,
I have a Z* report in our company, in the selection screen there is a period field (Month and Year) and this report running in background job periodically. My Question is how i can set for Month field become dynamic follow month value of date when this report executed ?
Example :
When Z* report running in background on 16.04.2008, Month Value will be 04 and when running on 16.05.2008, Month Value will be 05.
Please advice.
Regards
Gunawan -
What value for parameter Workspace when run function RSAQ_DELETE_QUERY?
Run function RSAQ_DELETE_QUERY to delete a query, it requires to input a Workspace value, what's that? and which value we should input for this parameter Workspace?
ThanksHi Kevin,
I think you can just leave it space. In the popup, don't enter a value and press enter.
Siggi
PS: Don't forget, this is not a tested solution.
Message was edited by: Siegfried Szameitat -
BPEL : Setting the default start value for instance ID
The instance ID for the processes are generated by the system, is it possible to set the starting value for the instance id. for eg: when I deployed a new process on a fresh installation and created an instance through BPEL console, it created a new instance with instance ID #1.
Is it possible for me to start the value from a different number say "5000"Hi ashutosh,
I think you can achieve this by writing a small java code in this Java Embedding activity.
For using Java Embed in BPEL, you can refer to the following blog:
http://technology.amis.nl/blog/?p=2387
Cheers,
Abhi... -
How to place multiple characteristic values for a single Report line
hi friends,
I want to display a report with multiple characteristc values in different columns for each instance, For example there are 2 instances and they have multiple characteristics , so all characteristics of each instance should be displayed in multiple columns in one by one in the same row.
Thanks in advance.
RK
Message was edited by:
RKHi RK,
Try this it may help you for multiple values for one instance....
*Type-pools
TYPE-POOLS: slis.
Data declarations.
DATA: BEGIN OF t_vbak OCCURS 0,
vbeln TYPE vbeln,
bstnk TYPE vbak-bstnk,
erdat TYPE vbak-erdat,
kunnr TYPE vbak-kunnr,
END OF t_vbak.
DATA: BEGIN OF t_vbap OCCURS 0,
vbeln TYPE vbeln,
matnr TYPE vbap-matnr,
netpr TYPE vbap-netpr,
waerk TYPE vbap-waerk,
kwmeng TYPE vbap-kwmeng,
meins TYPE vbap-meins,
END OF t_vbap.
DATA: t_fieldcatalog1 TYPE slis_t_fieldcat_alv.
DATA: t_fieldcatalog2 TYPE slis_t_fieldcat_alv.
DATA: v_repid TYPE syrepid.
DATA: s_layout TYPE slis_layout_alv.
DATA: v_tabname TYPE slis_tabname.
DATA: t_events TYPE slis_t_event.
start-of-selection event.
START-OF-SELECTION.
v_repid = sy-repid.
Get the fieldcatalog for the first block
PERFORM get_fieldcat1 CHANGING t_fieldcatalog1.
Get the fieldcatalog for the second block
PERFORM get_fieldcat2 CHANGING t_fieldcatalog2.
Get the data for the first block
SELECT vbeln bstnk erdat kunnr UP TO 10 ROWS
INTO TABLE t_vbak
FROM vbak WHERE vbeln > '0060000100'.
Get the data for the second block
SELECT vbeln matnr netpr waerk kwmeng meins UP TO 10
ROWS
INTO TABLE t_vbap
FROM vbap WHERE vbeln > '0060000100'.
init
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = v_repid.
First block
v_tabname = 'ITAB1'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog1
i_tabname = v_tabname
it_events = t_events
TABLES
t_outtab = t_vbak.
Second block
v_tabname = 'ITAB2'.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = s_layout
it_fieldcat = t_fieldcatalog2
i_tabname = v_tabname
it_events = t_events
TABLES
t_outtab = t_vbap.
*Display
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
FORM GET_FIELDCAT1
Get the field catalog for the first block
FORM get_fieldcat1 CHANGING lt_fieldcatalog TYPE
slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
Order number
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'VBELN'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Customer purchase order.
s_fieldcatalog-col_pos = '2'.
s_fieldcatalog-fieldname = 'BSTNK'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'BSTNK'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Creation date.
s_fieldcatalog-col_pos = '3'.
s_fieldcatalog-fieldname = 'ERDAT'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'ERDAT'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Customer
s_fieldcatalog-col_pos = '4'.
s_fieldcatalog-fieldname = 'KUNNR'.
s_fieldcatalog-tabname = 'T_VBAK'.
s_fieldcatalog-ref_tabname = 'VBAK'.
s_fieldcatalog-ref_fieldname = 'KUNNR'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
ENDFORM.
FORM GET_FIELDCAT2
Get the field catalog for the second block
FORM get_fieldcat2 CHANGING lt_fieldcatalog TYPE
slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
Order number
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'VBELN'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Material number
s_fieldcatalog-col_pos = '2'.
s_fieldcatalog-fieldname = 'MATNR'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'MATNR'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Net price
s_fieldcatalog-col_pos = '3'.
s_fieldcatalog-fieldname = 'NETPR'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'NETPR'.
s_fieldcatalog-cfieldname = 'WAERK'.
s_fieldcatalog-ctabname = 'T_VBAP'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Currency.
s_fieldcatalog-col_pos = '4'.
s_fieldcatalog-fieldname = 'WAERK'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'WAERK'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
Quantity
s_fieldcatalog-col_pos = '5'.
s_fieldcatalog-fieldname = 'KWMENG'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'KWMENG'.
s_fieldcatalog-qfieldname = 'MEINS'.
s_fieldcatalog-qtabname = 'T_VBAP'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
UOM
s_fieldcatalog-col_pos = '6'.
s_fieldcatalog-fieldname = 'MEINS'.
s_fieldcatalog-tabname = 'T_VBAP'.
s_fieldcatalog-ref_tabname = 'VBAP'.
s_fieldcatalog-ref_fieldname = 'MEINS'.
APPEND s_fieldcatalog TO lt_fieldcatalog.
CLEAR s_fieldcatalog.
ENDFORM.
Plz Reward points if contents are useful,,,
Regards,
Mandeep. -
Reset or Edit IPTC Fields Stored Values
Previous values used in IPTC fields are stored so that values can be auto-filled as a field is entered. I would like to remove some of the "stored values" for a field. How can I do this?
Thanks,You can batch change. Select the photos you want to edit, batch change, leave the field empty, and check the "replace" checkbox.
Maybe you are looking for
-
Update kernel and recieved a "Machine check error"
I was on Vacation this last weekend but was finally able to update today. Upgrade seemd fine, issued reboot command and instead of my normal reboot I was greeted with "machine check error" flashing in my upper left hand corner. Syslinux never came up
-
Can't sign in using any 3rd party email client with my iCloud account on any Mac or any other Mac. My iCloud will only work with Mail.app. All the clients I tried work perfectly well as long as I sign in with somebody else's iCloud account. But mine
-
How do I fix Elements 8 crash on start-up?
When Elements 8 starts, it immediatly crashes and goes to 'crash report' which I have submitted dozens of times. It will not startup in SafeMode either. Win 7 Home Premium, RAM 8 Gb.
-
"Incompatiable initial and maximum heap sizes specified" error
Hi, Using the command below: java -jar -Xms128m myjar.jar I get the following errors: "Error occurred during initialization of VM" "Incompatiable initial and maximum heap sizes specified" but if I take off the initial heap size parameter, just run: j
-
Exception: java.util.ConcurrentModificationException
We are using BEA WebLogic 8.1 SP 3. Sometimes on application machines appear following error: Exception: java.util.ConcurrentModificationException <2007-01-04 16:34:20 CET> <Error> <Management> <BEA-140001> <An error occurred whil