Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I charAt In a Input with a variable length, without getting the StringIndexOutOfBoundsExcepti

DynamiAug 16 2017 — edited Aug 21 2017

Hello. I've been trying to make a timer in an applet, by making it

1. You input the Hours:Minutes:Seconds

2. The program will separate them into different ints.

3. It will subtract 1 from the "Sec" Int every second, and when Sec runs out it will subtract from Min, And when it ends it will subtract from Hour, and at last, Play a sound.

But, because not always you will have Hours or Minutes on the timer, when I try to use charAt to extract the digits (on the second step) some times it throws a StringIndexOutOfBoundsException.

I'm probably doing the unefficient way, and I'm certain that I have more than 1 mistake in my code.

I am not asking someone to spoonfeed the code. But I would really appreciate if someone could enlighten on what I'm doing wrong here.

Thanks in advance.

(Also, this code is uncompilable. But I will ask about that in another discussion.)

  private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                           

        int HMS = Integer.parseInt(jTextField1.getText());

      String HourMinSec = Integer.toString(HMS);

if(HourMinSec.regionMatches(0,"00000",0,5)){

     int Sec = (int) HourMinSec.charAt(0);

     int Min = 0;

     int Hour = 0;

     } else

{ if (HourMinSec.regionMatches(0,"0000",0,4)){

     int Sec = (int) HourMinSec.charAt(0) * 10 + (int) HourMinSec.charAt(1);

     int Min = 0;

     int Hour = 0;} else{

   if (HourMinSec.regionMatches(0,"000",0,4)){

     int Sec = (int) HourMinSec.charAt(1) * 10 + (int) HourMinSec.charAt(2);

     int Min = (int) HourMinSec.charAt(0);

     int Hour = 0;}

     else {

      if(HourMinSec.regionMatches(0,"00",0,2)){ 

      int Sec = (int) HourMinSec.charAt(2) * 10 + (int) HourMinSec.charAt(3);

      int Min = (int) HourMinSec.charAt(0) * 10 + (int) HourMinSec.charAt(1);

      int Hour = 0;

      } else {

      if(HourMinSec.regionMatches(0,"0",0,1)){ 

      int Sec = (int) HourMinSec.charAt(3) * 10 + (int) HourMinSec.charAt(4);

      int Min = (int) HourMinSec.charAt(1) * 10 + (int) HourMinSec.charAt(2);

      int Hour =(int) HourMinSec.charAt(0);

      } else {

      int Sec = (int) HourMinSec.charAt(4) * 10 + (int) HourMinSec.charAt(5);

      int Min = (int) HourMinSec.charAt(2) * 10 + (int) HourMinSec.charAt(3);

      int Hour =(int) HourMinSec.charAt(0) * 10 + (int) HourMinSec.charAt(1);}}}}

      while(Sec != 0 || Min != 0 || Hour != 0){

          Thread.sleep(9);

        Sec -= 1;

        if(Sec == 0){

         Min -= 1;

          Sec = 60;}

        if(Min == 0){

            Hour -= 1;

            Min = 59;

        }

      jTextField1.setText(Hour + ":" + Min + ":" + Sec);

    }

     

    }                          

This post has been answered by mNem on Aug 17 2017
Jump to Answer

Comments

GregV

Hi,
Does it fail exactly at the DBMS_DATAPUMP.open line or you're getting the error from an exception block?
Usually the "job does not exist" error is a consequence of terminating a job that hasn't been created due to another error. Can you post the code?

User_H3J7U

Datapump creates the table based on job name. Table format may deffers accross databse versions.

User_TK218

@gregv This is how the code looks the code doesn't reach the line DBMS_OUTPUT.put_line('Job created') it fails on open and moves to exception

nFlashbackSCN := timestamp_to_scn(SYSDATE);
DBMS_OUTPUT.put_line('Starting Backup process');
hdpBackupJob := DBMS_DataPump.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', remote_link => NULL, job_name => 'J$AIM_BACKUP', VERSION => 'LATEST');
DBMS_OUTPUT.put_line('Job created');
DBMS_DataPump.add_file(handle => hdpBackupJob,
filename => sDumpFileName,
DIRECTORY => sBackupDirectory,
filesize => sFileSize,
reusefile => nReuseFile);
DBMS_DataPump.add_file(handle => hdpBackupJob,
filename => sLogFileName,
DIRECTORY => sBackupDirectory,
filetype => DBMS_DataPump.KU$_FILE_TYPE_LOG_FILE,
reusefile => nReuseFile);
-- consistent export
DBMS_DataPump.set_parameter(handle => hdpBackupJob, NAME => 'FLASHBACK_SCN', VALUE => nFlashbackSCN);
IF sJobMode = 'SCHEMA'
AND sSchemaName IS NOT NULL
THEN
DBMS_DataPump.metadata_filter(handle => hdpBackupJob, NAME => 'SCHEMA_EXPR', VALUE => 'IN (' || sSchemaName || ')');
END IF;

So this is how the code looks and

GregV

Can you show the exception's handler code as well?

User_TK218

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ( 'Error raised: '|| DBMS_UTILITY.FORMAT_ERROR_BACKTRACE || ' - '||sqlerrm);
AIM_DBS.P$Rollback;
BEGIN
DBMS_DataPump.stop_job(handle => hdpBackupJob, IMMEDIATE => 1, keep_master => 0, DELAY => 0);
AIM_DBS.P$Commit;
END;

GregV

Thanks. That's what I was trying to tell you. Here this is the stop_job instruction that produces the error, because the job doesn't exist in fact. SO to get the real error, comment out the DBMS_DataPump.stop_job line.

User_TK218

@gregv Sorry for the delay I tried commenting that line mentioning
DBMS_DataPump.stop_job(handle => hdpBackupJob, IMMEDIATE => 1, keep_master => 0, DELAY => 0);
and still getting the same error
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.DBMS_DATAPUMP", line 1852
ORA-06512: at "SYS.DBMS_DATAPUMP", line 6833
ORA-06512: at "AIMIM.AIM_BACKUP", line 1034

  • ORA-31626: job does not exist

Now the difference from the past is the line
ORA-06512: at "AIMIM.AIM_BACKUP", line 1034
exactly points to the open function.

Solomon Yakobson

Error is very misleading. DBMS_DATAPUMP.OPEN creates master table. And ORA-31626: job does not exist is raised when Oracle can't create master table:

SQL> revoke create table from u1;

Revoke succeeded.

SQL> connect u1@pdb1sol122

Enter password:

Connected.

SQL> exec DBMS_OUTPUT.PUT_LINE(DBMS_DataPump.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', remote_link => NULL, job_name => 'J$AIM_BACKUP', VERSION => 'LATEST'));

BEGIN DBMS_OUTPUT.PUT_LINE(DBMS_DataPump.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', remote_link => NULL, job_name => 'J$AIM_BACKUP', VERSION => 'LATEST')); END;

*

ERROR at line 1:

ORA-31626: job does not exist

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79

ORA-06512: at "SYS.DBMS_DATAPUMP", line 1852

ORA-06512: at "SYS.DBMS_DATAPUMP", line 6833

ORA-06512: at line 1

SQL> connect scott@pdb1sol122

Enter password:

Connected.

SQL> grant create table to u1;

Grant succeeded.

SQL> connect u1@pdb1sol122

Enter password:

Connected.

SQL> exec DBMS_OUTPUT.PUT_LINE(DBMS_DataPump.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', remote_link => NULL, job_name => 'J$AIM_BACKUP', VERSION => 'LATEST'));

PL/SQL procedure successfully completed.

SQL>

SY,

User_TK218

@solomon-yakobson Yeah it worked for some time as you described in sqlplus mode in command prompt for later it also stopped working in command prompt itself. Also, whenever I try to run the procedure including this code as the same user from the SQL developer it is showing the same error for me. Is there something related to the pluggable database? Or because I am running the procedure in the scheduled job?

Solomon Yakobson

What is stream pool size?
SY.

User_TK218

@solomon-yakobson I checked the streams_pool_Size using the sqlplus
SQL> show parameter STREAMS_POOL_SIZE;
NAME TYPE VALUE
------------------------------------ -----------
streams_pool_size big integer 0

Solomon Yakobson

And what about SGA_TARGET? Most likely is also set to zero. If so, you need to set streams pool size to say 40M.
SY.

User_TK218

@solomon-yakobson Yes, As you said SGA_TARGET is also zero(attached below). I will try to set STREAMS_POOL_SIZE=40M and will let you know.
NAME TYPE VALUE
---------- ----------- -----
sga_target big integer 0

User_TK218

@solomon-yakobson Sorry for the late reply altering the streams_pool_size parametet, it didn't work for me either. I also granted privileges like
grant dba to AIMIM;
grant all privileges to AIMIM;
grant sysdba to AIMIM;
grant sysbackup to AIMIM;
commit;
But none of them helped me in creating the job.

Solomon Yakobson

Double-check streams pool size:

SELECT VALUE FROM GV$PARAMETER WHERE NAME = 'streams_pool_size'
/

I assume

DBMS_DataPump.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', remote_link => NULL, job_name => 'J$AIM_BACKUP', VERSION => 'LATEST');

is in stored procedure, so keep in mind roles are ignored (unless stored procedure is AUTHID CURRENT_USER). Therefore double-check stored procedure owner (not caller) is directly (not via role) granted CREATE TABLE.
Double-check stored procedure owner (not caller) has quota on its default tablespace.
Restart database. It could be background process QMNC is dead for some reason (e.g. cancelled shutdown).
SY.

1 - 15
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 18 2017
Added on Aug 16 2017
5 comments
556 views