我試圖編譯一個簡單的Helloworld程序BADA,但通過命令prompt.After編譯我可以得到的錯誤爲 c:/Helloworld/src/Helloworld.cpp: 12:error:'Osp :: App :: Application HelloWorld :: CreateInstance()'的原型不匹配類'HelloWorld'中的任何一個 C:/Helloworld/inc/HelloWorld.h:21:error:candidate is:static Osp :: App :: Application * HelloWorld :: CreateInstance() 任何機構都可以幫助完成需要完成的任務。 感謝從命令提示符編譯BADA簡單helloworld程序,並得到錯誤
代碼Helloworld.h
#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__
#include <FBase.h>
#include <FGraphics.h>
#include <FLocales.h>
#include <FSystem.h>
#include <FApp.h>
using namespace Osp::Base;
using namespace Osp::Graphics;
using namespace Osp::Locales;
using namespace Osp::System;
using namespace Osp::App;
class HelloWorld :
public Application // must inherit from Application class
{
public:
// The application must have a factory method that creates an instance of the application.
static Application* CreateInstance(void);
public:
HelloWorld();
~HelloWorld();
public:
// The application must provide its name.
String GetAppName(void) const;
protected:
// The application must provide its ID.
AppId GetAppId(void) const;
AppSecret GetAppSecret(void) const;
public:
// This method is called when the application is initializing.
bool OnAppInitializing(AppRegistry& appRegistry);
// This method is called when the application is terminating.
bool OnAppTerminating(AppRegistry& appRegistry);
// Thie method is called when the application is brought to the foreground
void OnForeground(void);
// This method is called when the application is sent to the background.
void OnBackground(void);
// This method is called when the application has little available memory.
void OnLowMemory(void);
// This method is called when the device's battery level changes.
void OnBatteryLevelChanged(BatteryLevel batteryLevel);
};
#endif
代碼Helloworld.cpp
#include "HelloWorld.h"
HelloWorld::HelloWorld()
{
}
HelloWorld::~HelloWorld()
{
}
Application*
HelloWorld::CreateInstance(void)
{
// You can create the instance through another constructor.
return new HelloWorld();
}
String
HelloWorld::GetAppName(void) const
{
static String appName(L"HelloWorld");
return appName;
}
AppId
HelloWorld::GetAppId(void) const
{
static AppId appId(L"93bt1p123e");
return appId;
}
AppSecret
HelloWorld::GetAppSecret(void) const
{
static AppSecret appSecret(L"9C645DDBA19C71BAD1204DA4DAA7A0B9");
return appSecret;
}
bool
HelloWorld::OnAppInitializing(AppRegistry& appRegistry)
{
// TODO:
// Initialization including UI construction can be done here.
// Load the application's latest data, if necessary.
// If this method is successful, return true; otherwise, return false.
return true;
}
bool
HelloWorld::OnAppTerminating(AppRegistry& appRegistry)
{
// TODO:
// Deallocate or close any resources still alive.
// Save the application's current states, if applicable.
// If this method is successful, return true; otherwise, return false.
return true;
}
void
HelloWorld::OnForeground(void)
{
result r = E_SUCCESS;
Canvas* pCanvas = GetAppFrame()->GetCanvasN();
if(pCanvas == null)
return;
Font* pFont = new Font();
pFont->Construct(FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 50);
pCanvas->SetFont(*pFont);
r = pCanvas->DrawText(Point(30, 30), GetAppName());
if (IsFailed(r))
{
AppLog("pCanvas->DrawText() failed.\n");
delete pCanvas;
return;
}
r = pCanvas->Show();
if (IsFailed(r))
{ AppLog("pCanvas->Show() failed.\n");
delete pCanvas;
return;
}
delete pCanvas;
}
void
HelloWorld::OnBackground(void)
{
}
void
HelloWorld::OnLowMemory(void)
{
// TODO:
// Deallocate as many resources as possible.
}
void
HelloWorld::OnBatteryLevelChanged(BatteryLevel batteryLevel)
{
// TODO:
// It is recommended that the application save its data,
// and terminate itself if the application consumes much battery
}
代碼Helloworldentry.cpp
/**
* OSP Application entry point(OspMain) introduced.
*/
#include <fapp.h>
#include "HelloWorld.h"
using namespace Osp::Base::Collection;
extern "C"
{
__declspec(dllexport) void OspMain(int hInstance, int argc, char *argv[]);
}
/**
* Entry function of OSP Application which is called by the operating system.
*/
extern "C" {
void OspMain(int hInstance, int argc, char *argv[])
{
AppLog("OspMain() Started. \n");
result r = E_SUCCESS;
ArrayList* pArgs = new ArrayList();
pArgs->Construct();
for (int i = 0; i < argc; i++)
{
String* pEachArg = new String(argv[i]);
pArgs->Add(*pEachArg);
}
r = Osp::App::Application::Execute(HelloWorld::CreateInstance, pArgs);
if (IsFailed(r))
{
AppLog("Application execution has failed.\n");
}
if (pArgs)
{
pArgs->RemoveAll(true);
delete pArgs;
}
AppLog("OspMain() Ended. \n");
}
}
您好,感謝您的幫助。 現在經過一些改變後,我得到的錯誤爲 c:/Helloworld/src/Helloworld.cpp:在靜態成員函數'static Osp :: App :: Ap plication * HelloWorld :: CreateInstance()'中: c:/Helloworld/src/Helloworld.cpp:15:錯誤:無法分配對象的抽象 t型'HelloWorld' C:/Helloworld/inc/HelloWorld.h:18:注意:因爲以下虛擬函數 ns在'HelloWorld'中是純粹的: C:/bada/1.0.0b3/include/FAppApplication.h:344:note:virtual bool Osp :: App :: A pplication :: OnAppTerminating(Osp :: App :: AppRegistry& bool)..我發佈了下面的代碼 – Suvin 2010-08-30 13:55:48
Application類定義了一個名爲「OnAppTerminating」的純虛函數,它帶有兩個參數,一個是「AppRegistry」 '和'bool'。爲了創建你的'HelloWorld'類的實例,你必須實現這個方法。你已經實現了一個名爲'OnAppTerminating'的方法,但是它沒有使用正確數量的參數。 – 2010-08-30 14:48:48
現在再次糾正錯誤後,我得到的錯誤是 c:/Helloworld/src/Helloworld.cpp:18:error:no'Osp :: App :: Application * HelloWorld :: CreateInstance()'成員函數聲明在類'HelloWorld' 已經嘗試了很多事情,但無法弄清楚。謝謝 – Suvin 2010-08-31 07:18:48