×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Question What is the error ??

    hello all,
    This might come in really stupid but i am not able to find out what's wrong with this code ...

    i am creating a console application which is supposed to have some timer based activities.. i created a timer and an active object and am trying to call the timer after specific time interval. but the application crashes . and it crashed somewhere it is not supposed to ..

    the header file ..
    Code:
    /*
     ============================================================================
     Name		: Cobra_Console.h
     Author	  : Abhishek karmakar
     Copyright   : Please stay in peace.	
     Description : Exe header file
     ============================================================================
     */
    
    #ifndef __COBRA_CONSOLE_H__
    #define __COBRA_CONSOLE_H__
    
    //  Include Files
    #include "ActiveKeyObserver.h"
    #include "ActiveTimer.h";
    #include "ActiveTimerNotify.h"
    #include "CRSendAsSender.h"
    #include "CellidDetector.h"
    #include <e32base.h>
    
    class CExampleScheduler : public CActiveScheduler
    	{
    public:
    	void Error(TInt aError) const
    		{
    		_LIT(KMsgSchedErr,"CExampleScheduler-error");
    		User::Panic(KMsgSchedErr, aError);
    		}
    	};
    
    class CCobra_Console : public CBase,MActiveTimerNotify,MActiveKeyPressNotify
    	{
    public:
    	static CCobra_Console* NewLC();
    	~CCobra_Console();
    public:
    	TInt StartL();
    	void TimerComplete(TInt aError);
    	void KeyHasBeenPressed(TChar aChar);;
    private:
    	CCobra_Console();
    	void ConstructL();
    public:
    		CActiveTimer* iTimer;
    		CActiveKeyObserver* iKeyActiveObserver;
    		TInt iTimerActive;
    		TInt iShowHello;
    	};
    //  Function Prototypes
    
    GLDEF_C TInt E32Main();
    
    #endif  // __COBRA_CONSOLE_H__
    the cpp file

    Code:
    /*
     ============================================================================
     Name		: Cobra_Console.cpp
     Author	  : Abhishek karmakar
     Copyright   : Please stay in peace.	
     Description : Exe source file
     ============================================================================
     */
    //  Include Files  
    #include "Cobra_Console.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>			// Console
    //  Constants
    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");
    //  Global Variables
    LOCAL_D CConsoleBase* console; // write all messages to this
    //  Local Functions
    LOCAL_C void MainL()
    	{
    	//
    	// add your program code here, example code below
    	//
    	console->Write(_L("Hello, world!\n"));
    	}
    
    LOCAL_C void DoStartL()
    	{
    	// Create active scheduler (to run active objects)
    	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    	CleanupStack::PushL(scheduler);
    	CActiveScheduler::Install(scheduler);
    
    	MainL();
    
    	// Delete active scheduler
    	CleanupStack::PopAndDestroy(scheduler);
    	}
    
    //  Global Functions
    
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    	// Create output console
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
    							KConsFullScreen, KConsFullScreen)));
    	if (createError)
    		return createError;
    	// Run application code inside TRAP harness, wait keypress when terminated
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    		{
    		console->Printf(KTextFailed, mainError);
    		}
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    	
    	CCobra_Console* cobra = CCobra_Console::NewLC();
    	CleanupStack::PushL(cobra);
    	cobra->StartL();
    	CleanupStack::Pop(cobra);
    	
    
    	//delete console;
    	//delete cleanup;
    	//__UHEAP_MARKEND;
    	//return KErrNone;
    	return 0;
    	}
    
    CCobra_Console* CCobra_Console::NewLC()
    	{
    	CCobra_Console* self = new (ELeave) CCobra_Console;
    	CleanupStack::PushL(self);
    	return self;
    	}
    
    CCobra_Console::CCobra_Console()
    	{
    
    	}
    CCobra_Console::~CCobra_Console()
    	{
    
    	}
    
    TInt CCobra_Console::StartL()
    	{
    	// Construct and install the active scheduler
    	CExampleScheduler* exampleScheduler = new (ELeave) CExampleScheduler;
    	// Push onto the cleanup stack
    	CleanupStack::PushL(exampleScheduler);
    	// Install as the active scheduler
    	CActiveScheduler::Install(exampleScheduler);
    	iTimer = CActiveTimer::NewL(*this);
    	iShowHello = 1;
    	iTimer->After(10000000);
    	// Start the CActiveScheduler where we wait for the event
    	CActiveScheduler::Start();
    	CleanupStack::PopAndDestroy(1); // destroy exampleScheduler, does it destroy if not need to fix
    	return KErrNone;
    	}
    void CCobra_Console::TimerComplete(TInt aError)
    	{
    
    	console->Printf(_L("timer is elapsed"));
    
    	}
    void CCobra_Console::KeyHasBeenPressed(TChar aChar)
    	{
    
    	}
    when i debug the application it gets stuck in the Main
    it goes to the line ..
    CCobra_Console* cobra = CCobra_Console::NewLC();

    then goes to the NewLC() function.
    and exits while executing the following line ..

    CleanupStack::PushL(self);

    any ideas ..

    please help ..

    many thanks ..



    and then ..
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

  2. #2
    Registered User
    Join Date
    Oct 2007
    Location
    Noida
    Posts
    152

    Red face Re: What is the error ??

    hi again,

    Well i was missing a TRAPD();

    so i did ..
    Code:
    TRAPD(error,CCobra_Console* cobra = CCobra_Console::NewLC();
    	CleanupStack::PushL(cobra);
    	cobra->StartL();
    	CleanupStack::Pop(cobra);
                     )
    if(error)
    {
    console->printf(error);
    
    }
    its working now ..
    Abhishek karmakar

    never- Never - NEVER -- !!! NEVER !!! GIVE UP

Similar Threads

  1. XMl Parser Implementation for Symbian
    By ittiam in forum Symbian
    Replies: 26
    Last Post: 2009-09-16, 05:26
  2. i cant build helloworld project
    By akhin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-12-22, 12:38
  3. Help with lnk2019 lnk1120 error
    By yuenfatt in forum Symbian
    Replies: 8
    Last Post: 2007-08-24, 08:21
  4. My BuilderX (with S60 SDK 2.1.NET MS version) cannot build ARMI UREL
    By danielvidonyi@hotmail.com in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-05-04, 21:30
  5. User break point error in Grid
    By ag24master in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-08-07, 08:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×