DBMS_XMLQuery problems
The xmlquery is creating and extra "ITEM" tag when using the object view below.
Any Ideas?
Thanks
CREATE OR REPLACE VIEW sjs.arrest_obj_view
AS SELECT a.a_date AS "ArrestDate",
NVL(a.a_photo_num,'NULL') AS "PhotographNumber",
NVL(a.a_division,'NULL') AS "AgencyDivision",
'MODEL MAPPING PROBLEM' AS "ArrestType",
NVL(agcy.agcy_ori,'NULL') AS "ArrestingAgency",
a.a_id AS "ArrestNumber",
NVL(o.o_number,'NULL') AS "AssistingOfficerID",
'MODEL MAPPING PROBLEM' AS "CJTN",
CAST(MULTISET(SELECT l.lu_name AS "WeaponForce"
FROM sjs.arrestweapons awm,
sjs.lookuptable l
WHERE awm.a_id = a.a_id
AND awm.weapons_id = lu_id (+)) AS arrest_weapons_type)
AS "ArrestWeapons"
FROM sjs.arrest a,
sjs.agency agcy,
sjs.officers o
WHERE a.agcy_id = agcy.agcy_id (+)
AND a.o_assist_id = o.o_id (+)
<ROWSET>
<ROW num="1">
<InterfaceTransaction>ADD</InterfaceTransaction>
<ArrestDate>6/11/1996 16:45:0</ArrestDate>
<PhotographNumber>NULL</PhotographNumber>
<AgencyDivision>NULL</AgencyDivision>
<ArrestType>MODEL MAPPING PROBLEM</ArrestType>
<ArrestingAgency>NY0353400</ArrestingAgency>
<ArrestNumber>1</ArrestNumber>
<AssistingOfficerID>NULL</AssistingOfficerID>
<CJTN>MODEL MAPPING PROBLEM</CJTN>
<ArrestWeapons>
<ArrestWeapons_ITEM>
<WeaponForce>NONE/NOT APPLICABLE</WeaponForce>
</ArrestWeapons_ITEM>
</ArrestWeapons>
</ROW>
</ROWSET>
Hi Frank,
Please chech your object view definition.
are u sure that there will be sigle value populated in the set ArrestWeapons?? your definition says that there will be multiple values and thais is how xmlquery typically handles the nesting.
inside the <ArrestWeapons> ,there will be no of <ArrestWeapons_ITEM> nestings equal to the no of records.
if u do not want this item tag there or two options.
1)try canging the object view definition.i am not sure about your requirements of the xml query. the heriarchy can also be acheived by nested cursors and by objects/nested tables.
2)u will have to manipulate the clob while generating the xml file and delete the unwanted tags.
feel free to post any further queries...
Similar Messages
-
Dbms_xmlquery.getxml problem
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM --------- ---------- --------- ---------- --------- ---------- ---------- ---------- --------- ------------
7369 SMITH CLERK 7902 17-DEC-80 800 20
14 rows selected.
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
I'm just wondering why the query output XML has EMPNO alone, and not the other column data.Please help.
Thanks,
BhagatIt's because of the parameter settings in SQL*Plus. It's just not showing the whole output for you...
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
SQL> set long 2000
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>12/17/1980 0:0:0</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
</ROWSET>
SQL> -
Problem with generating xml and nested cursor (ora-600)
I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
When I execute the following command, I get a ORA-600 error:
select dbms_xmlquery.getxml('select mst_id
, mst_source
, cursor(select per.*
, cursor(select ftm_fdf_number
, ftm_value
from t_feature_master
where ftm_mstr_id = pers_master_id ) as features
from t_person per
where pers_master_id = mst_id ) as persons
from f_master
where mst_id = 3059435')
from dual;
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
</ERROR>
The problem is the second cursor (t_feature_master).
I want to generate this:
<master>
<..>
<persons>
<..>
<features>
<..>
</features>
</persons>
<persons>
<..>
<features>
<..>
</features>
</persons>
</master>
If i execute the select-statement in sql-plus, then I get the next result.
MST_ID MST_SOURCE PERSONS
3059435 GG CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
3059435 W. Name
CURSOR STATEMENT : 15
FTM_FDF_NUMBER FTM_VALUE
1 [email protected]
10 ....
I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
Is this a bug and do somebody know a workaround?Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.
-
Error while executing DBMS_XMLQUERY
I'm using a Function to generate a XML file for the given query.
When the functions calls DBMS_XMLQUERY to access a method named : setXSLT ,where it further calls to p_setXSLT .The error comes in p_setXSLT
The error is:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoSuchMethodError
The code in the p_setXSLT is:
PROCEDURE setXSLT(ctxHdl IN ctxType, stylesheet IN CLOB, ref IN VARCHAR2 := null) IS
begin
p_setXSLT(ctxHdl, stylesheet, ref);
end setXSLT;
Some1 help on this plz///
Regds,
Jignesh SDear I am also facing the same problem. Did you get any solution for that...
My problem is like this, i created a java stored procedure which returns XML Output. The java class standalone is working fine.
Thanks in advance.
Ravi kumar varma.N -
Problem for xml generation using DBMS_XMLGEN
Hi All,
i have problem during xml generation using Any help would be highly appreciate
how could we publish xml data using data base API DBMS_XMLGEN in oracle applications (APPS) i.e. at 'View Output" using
Any help would be highly appreciate.
Let me know if need more explanation, this is High priority for me.
Thanks and Regards,
[email protected]
Message was edited by:
user553699You can set the null attribute to true , so that the tag appears in your XML
see the statement in Bold.
DECLARE
queryCtx dbms_xmlquery.ctxType;
result CLOB;
BEGIN
-- set up the query context
queryCtx := dbms_xmlquery.newContext(
'SELECT empno "EMP_NO"
, ename "NAME"
, deptno "DEPT_NO"
, comm "COMM"
FROM scott.emp
WHERE deptno = :DEPTNO'
dbms_xmlquery.setRowTag(
queryCtx
, 'EMP'
dbms_xmlquery.setRowSetTag(
queryCtx
, 'EMPSET'
DBMS_XMLQUERY.useNullAttributeIndicator(queryCtx,true);
dbms_xmlquery.setBindValue(
queryCtx
, 'DEPTNO'
, 30
result := dbms_xmlquery.getXml(queryCtx);
insert into clobtable values(result);commit;
dbms_xmlquery.closeContext(queryCtx);
END;
select * from clobtable
<?xml version = '1.0'?>
<EMPSET>
<EMP num="1">
<EMP_NO>7499</EMP_NO>
<NAME>ALLEN</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>300</COMM>
</EMP>
<EMP num="2">
<EMP_NO>7521</EMP_NO>
<NAME>WARD</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>500</COMM>
</EMP>
<EMP num="3">
<EMP_NO>7654</EMP_NO>
<NAME>MARTIN</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>1400</COMM>
</EMP>
<EMP num="4">
<EMP_NO>7698</EMP_NO>
<NAME>BLAKE</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM NULL="YES"/>
</EMP>
<EMP num="5">
<EMP_NO>7844</EMP_NO>
<NAME>TURNER</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>0</COMM>
</EMP>
<EMP num="6">
<EMP_NO>7900</EMP_NO>
<NAME>JAMES</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM NULL="YES"/>
</EMP>
</EMPSET>
http://sqltech.cl/doc/oracle9i/appdev.901/a89852/d_xmlque.htm -
DBMS_XMLQuery behavior when using stored function within cursor select
Consider the following SQL Statement
select t1.id
, t1.name
, cursor ( select t2.id
from tab t2
where t2.t1_id
= t1.id
and validate(t2.xyz,:bd1)
= 1
from tab t1
where t1.id = :bd2
DBMS_XMLQuery is used to create a context and to bind the appropriate values. In this case 'validate' is a stored function. I get the following error message upon execution:
ORA-29532: Java call terminated by uncaught Java exception:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
Issuing a similar statement in SQL*Plus works fine. I was wondering whether this is a known issue when using a stored function in the cursor select statement in the context of DBMS_XMLQuery or whether I'm doing something wrong.Hi Jan,
This problem has been identified and fixed. The fix should be available in the next release. Thank you for bringing this up to our attention.
visar -
"Missing IN or OUT parameter at index:: 1" - dbms_xmlquery vs dbms_xmlgen
It looks like DBMS_XMLQuery doesn't like bind variables among selected columns.
While DBMS_XMLGEN handles them without any problems.
A simple example:
-- xml query - fails
declare
ctx dbms_xmlquery.ctxHandle;
begin
ctx := dbms_xmlquery.newContext(
'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
dbms_xmlquery.setBindValue(ctx, 'r_max', 10);
dbms_output.put_line(dbms_xmlquery.getxml(ctx));
dbms_xmlquery.closeContext(ctx);
end;
The error is <ERROR>oracle.xml.sql.OracleXMLSQLException: Missing IN or OUT parameter at index:: 1</ERROR>
-- xml gen - works
declare
ctx dbms_xmlgen.ctxHandle;
begin
ctx := dbms_xmlgen.newContext(
'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
dbms_xmlgen.setBindValue(ctx, 'r_max', 10);
dbms_output.put_line(dbms_xmlgen.getxml(ctx));
dbms_xmlgen.closeContext(ctx);
end;
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - ProdLooks like you need two binds to accomplish your task:
SQL> declare
2 ctx dbms_xmlquery.ctxhandle;
3 begin
4 ctx := dbms_xmlquery.newcontext('select emp.*, :r_max1 the_end from emp where rownum <= :r_max2');
5 dbms_xmlquery.setbindvalue (ctx, 'r_max1', 4);
6 dbms_xmlquery.setbindvalue (ctx, 'r_max2', 4);
7 dbms_output.put_line (dbms_xmlquery.getxml (ctx));
8 dbms_xmlquery.clearbindvalues (ctx);
9 dbms_xmlquery.closecontext (ctx);
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>12/17/1980 0:0:0</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="2">
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>2/20/1981 0:0:0</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="3">
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>2/22/1981 0:0:0</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="4">
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>4/2/1981
0:0:0</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
<THE_END>4</THE_END>
</ROW>
</ROWSET>
PL/SQL procedure successfully completed. -
Hi All,
I'm having problems with the XML generation. The problem is that when we try to generate XML using a query, such as:
select xmlgen.getXML('select content_id, locale_id, content from bc_content_local where delete_p = ''0''',1) from dual;
It works fine so long as of the information retrieved by the query is ASCII. But if there are UTF8 characters in there, the
generation of the XML fails.
I wasn't actually getting an error message. It would work and return XML but as soon as the first UTF-8 character was encountered,
the XML just stopped.
Two questions:
1) Does the XML generation support UTF-8? 2)
If it does (I seem to remember hearing that it did) what has to be done so that this
works correctly?
We are using a UTF8 characterset we set during database creation. I have also tried setting up NLS_LANG in the client registrty to american_america.utf8 - but in both client and server I get teh same message.
Database: Oracle 8.1.7 Standard Edition on Sun-Solaris 2.8
Any help greatly appreciated,
Nilendu Misra
[email protected]Ok, I found we have DBMS_XMLQUERY installed on the schema other than SYS too. But when I issue the same statement using this package I get a different error:
SQL> select dbms_xmlquery.getXML('select content_id, locale_id, content
2 from bc_content_local where delete_p = ''0''',1) from dual;
select dbms_xmlquery.getXML('select content_id, locale_id, content
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NullPointerException
ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 212
ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 220
ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 210
ORA-06512: at "SYSTEM.DBMS_XMLQUERY", line 228
ORA-06512: at line 1
I tried searching the XML forum and Metalink but I found most of the reports on this nature of problem are still unanswered.
Thanks in appreciation,
Nilendu
null -
I have downloaded the tar xdk_plsql_9_0_1_0_0.tar file and installed
the XDK onto my 8.1.7.2 database on a sun sparc server.
My problem is this , for the user scott the following statement works fine in that it produces the xml output :
select dbms_xmlquery.getxml('select * from emp', 2) from dual;
However when I try to use the same package above as another user trying to generate xml on one of its tables , I get the following error:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
Both user scott and my "test user" have identical privileges, which includes the
JAVASYSPRIV and the JAVAUSERPRIV.
My question is this what do I have to do in order for another user to be able to use the
dbms_xmlquery without getting any problems?RTFM.
Function DBMS_XMLQUERY.GETXML takes 2 number parameters and returns a CLOB.
If you do a describe on DBMS_XMLQUERY you will find :
FUNCTION GETXML RETURNS CLOB
Argument Name Type In/Out Default?
CTX NUMBER IN
METATYPE NUMBER IN DEFAULT
You have to call DBMS_XMLQUERY.NEWCONTEXT and pass it the SQL statement. This function returns a CONTEXT ( number ) which you use in DBMS_XMLQUERY.GETXML. -
Mixed case parsing using DBMS_XMLquery
I have created a view using mixed case column names. However, when I use DBMS_XMLquery to pass the select "column_name" from table_name, it does not parse and does not work. However it works fine with passing 'select * from table_name'. Any idea how a mixed case column can be passed to dbms_xmlquery? Or any idea how a mixed case column name is passed in dynamic sql queries.
I found the problem. It was not with mixed case column names. Rather it was because of the NULL value returns from the sql query which the java procedure for transforming sql was not able to trap and throwing out exception.
However, still it is quite funny. If I use all the columns in the query or do select * , I get back the generated XML. If I just select a few columns, I get the error message
ORA-29532: Java call terminated by uncaught java exception (java.lang.NullPointerException
ORA-06512: at "SYS.DBMS_XMLQUERY" line 206
Any idea
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jinyu Wang ([email protected]):
Would you send the test case you are using for reproducing the problem?<HR></BLOCKQUOTE>
null -
DBMS_XMLQuery.setXSLT in XSU111 ver1_2_1 for Oracle 8.1.5
Hi, All
the problem is:
im using XSU111 ver1_2_1 for Oracle 8.1.5
below is some example whish throws an Error in SQL-Plus
(ORA-03113: end-of-file on communication channel)
when commented line is on
-- ++++ start of script ++++
create or replace function xsl_test return CLOB is
queryCtx DBMS_XMLquery.ctxType;
result CLOB := null;
result1 CLOB := null;
begin
queryCtx := DBMS_XMLQuery.newContext('select * from airport where rownum < 10');
--this line throws an Error DBMS_XMLQuery.setXSLT(queryCtx, 'http://localhost/xml/rowcol.xsl');
result := DBMS_XMLQuery.getXML(queryCtx);
DBMS_XMLQuery.closeContext(queryCtx);
return result;
end;
select xsl_test from dual;
-- ++++ end of script ++++
null8.1.5 went out of support on dec 31, 2000,
you will need to upgrade to a supported version to get any fixes for problems. -
Need help please DBMS_XMLQUERY
Hello ,
i am trying to generate a xml in a db orcle 9i release Release 9.0.1.4.0 so i don not have many of the new functionality
the code i am trying to execute is the foolowing
DECLARE
p_entityid LONG;
p_entitylegalname VARCHAR2(100);
p_businesstradenameone VARCHAR2(100);
p_businesstradenametwo VARCHAR2(100);
p_businesstradenamethree VARCHAR2(100);
p_dunsnumber NUMBER;
queryctx DBMS_XMLQUERY.ctxtype;
RESULT CLOB;
BEGIN
queryctx :=
SYS.DBMS_XMLQUERY.newcontext
('select :p_EntityID EntityID, :p_EntityLegalName EntityLegalName ,
cursor( select :p_BankAccountID BankAccountID ,
:p_BankCode BankCode
from dual ana) AS dt
from dual ana');
SYS.DBMS_XMLQUERY.setrowsettag(queryctx, 'CreateEntityRequest');
SYS.DBMS_XMLQUERY.setrowtag(queryctx, 'Entity');
SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_EntityID', 1);
SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_EntityLegalName', ' prueba');
SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_BankAccountID', 23);
SYS.DBMS_XMLQUERY.setbindvalue(queryctx, 'p_BankCode', '123');
RESULT := SYS.DBMS_XMLQUERY.getxml(queryctx);
printclobout(RESULT);
SYS.DBMS_XMLQUERY.closecontext(queryctx);
END;
these give me the following xml
| <?xml version = '1.0'?>
| <CreateEntityRequest>
| <Entity num="1">
| <ENTITYID>1</ENTITYID>
| <ENTITYLEGALNAME> prueba</ENTITYLEGALNAME>
| <DT>
| <DT_ROW num="1">
| <BANKACCOUNTID>23</BANKACCOUNTID>
| <BANKCODE>123</BANKCODE>
| </DT_ROW>
| </DT>
| </Entity>
| </CreateEntityRequest>
the problem that i have is it writes this tag <DT_ROW num="1"> that i do not want an also it puts in the tag <Entity num="1"> the num="1"
does sono one know how remove it
i am desperate many thanks
anaHello
I've read about the same problem on different places and everyone provides an alternative instead of the real solution.
After reading soms specs on the Oracle website, I found this simple solution:
dbms_xmlquery.setrowidattrname(query_ctx, NULL); -- default num
dbms_xmlquery.setrowidattrvalue(query_ctx, NULL);
Simply clear the default attribute (which is a constant of xmlquery) and it's value and you are set.
Kind Regards
Bjorn Ongenae
iAdvise Consulting -
Using Oracle 9i dbms_xmlquery in Oracle 8i
I have the following questions:
- Is it possible to use the Oracle 9i version of package dbms_xmlquery in Oracle 8i? Are there any known problems?
- What about the Oracle 8 ODBC driver: is it possible to transfer the same amount of bytes of an XML string in a CLOB from the database server to an ASP program?
I appreciate your response.Hi,
I think you may do so from Oracle 8.l.5 onwards. Ofcourse, you may have to download and install the XDK on the 8i server and grant rights to the xml objects to the users(by default they are owned by sys).
As far as the ODBC driver is concerned (though I am not sure) it should be possible because LOBs are streaming data and so, if the client is able to pull it, there shouldn't be any problems.
HTH
Elango. -
I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
Thank you in advance,
LeftyThis was one solution from the socket programming forum, have you tried this??
public Thread MyThread extends Thread{
boolean active = true;
public void run(){
ss.setSoTimeout(90);
while (active){
try{
serverSocket = ss.accept();
catch (SocketTimeoutException ste){
// do nothing
// interrupt thread
public void deactivate(){
active = false;
// you gotta sleep for a time longer than the
// accept() timeout to make sure that timeout is finished.
try{
sleep(91);
}catch (InterruptedException ie){
interrupt();
} -
A problem with Threads and MMapi
I am tring to execute a class based on Game canvas.
The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
The MIDI tone "Stammers".
How to over come the problem?
Thanks in advance
Kobi
See Code example below:
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
public class MainScreenCanvas extends GameCanvas implements Runnable {
private MainMIDlet parent;
private boolean mTrucking = false;
Image imgBackgound = null;
int imgBackgoundX = 0, imgBackgoundY = 0;
Player player;
public MainScreenCanvas(MainMIDlet parent)
super(true);
this.parent = parent;
try
imgBackgound = Image.createImage("/images/area03_bkg0.png");
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
catch(Exception e)
System.out.println(e.getMessage());
* starts thread
public void start()
mTrucking = true;
Thread t = new Thread(this);
t.start();
* stops thread
public void stop()
mTrucking = false;
public void play()
try
InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
player = Manager.createPlayer(is, "audio/midi");
player.setLoopCount(-1);
player.prefetch();
player.start();
catch(Exception e)
System.out.println(e.getMessage());
public void run()
Graphics g = getGraphics();
play();
while (true)
tick();
input();
render(g);
* responsible for object movements
private void tick()
* response to key input
private void input()
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0)
imgBackgoundX++;
if (imgBackgoundX > 0)
imgBackgoundX = 0;
if ((keyStates & RIGHT_PRESSED) != 0)
imgBackgoundX--;
if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
* Responsible for the drawing
* @param g
private void render(Graphics g)
g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
this.flushGraphics();
}You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
Regds,
SD
N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM
Maybe you are looking for
-
Windows 7 64-bit and need to install both 32bit and 64bit Oracle 11g client
Hello First I am sorry for asking what is probably a common knowledge answer from most in the forum. I just cannot find a straight forward answer searching these forums or via google. We have Windows 7 64-bit planned as our next desktop upgrade. We h
-
I bought a new Macbook Pro, how can I get my very old macbook cleared of my stuff so I can give it to my grandson. I just want him to be able to use it.
-
ERROR Cannot create target (optional) element - SUPPRESS value
HI, XI/PI experts! I am new in PI 7.1 (Ehp1 SP 7), previously work with PI 7.0. I faced with problem of mapping optional target element, when queue has just SUPPRESS element. I expected to suppressing mapping of the target element, but mapping progra
-
Can i buy a mac in USA with the discount(mac for education) with a acceptance cirtificate from a university in south africa? This will realy help me because there is a $500 dollar difirance between the us and south african price
-
Sharing recognition on network for new win7 computer
My youngest daughter received a pc w/windows 7 for christmas. she was given her older sister's IPod Nano with the music on it. I installed itunes 9 on the new computer. When I look at home sharing, I've gotten the new computer to find the other syste