【问题标题】:Error: allocating an object of abstract class type 'JIntent'错误:分配抽象类类型“JIntent”的对象
【发布时间】:2015-08-05 08:13:15
【问题描述】:

如何解决这个错误?

代码:

Intent *JIntent; //main.h
//menu.cpp
Intent = new JIntent(this); //Error

并创建类:

class TestClass
{
    public:
        JIntent *MyIntent;
        JService *MyService;
        virtual int FuncClass() = 0;
};

int TestClass::FuncClass() {
    MyIntent = new JIntent(this);
    MyService = new JService(this);

}

不起作用。我不明白这个。

【问题讨论】:

  • Pozharov 显示类 JIntent 的构造函数和你得到的错误信息。

标签: android c++ c++builder firemonkey


【解决方案1】:

JIntent 和JService 是抽象接口,不能直接实例化它们。对于JIntent,您必须改为实例化TJIntent 类,并将其分配给_di_JIntent 变量(它封装了接口来为您处理引用计数);

#include <Androidapi.JNI.App.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>

class TestClass
{
    public:
        _di_JIntent MyIntent;
        _di_JService MyService;
        virtual int FuncClass() = 0;
};

int TestClass::FuncClass() {
    MyIntent = new TJIntent;
    MyService = ...;
}

话虽如此,JService 代表 Android 的 Service 类。有一个伴随的TJService 类,但它是派生,而不是实例化。 Delphi/C++Builder 本身还不支持实现 Android 服务,尽管在技术上可以通过一些额外的工作(涉及 Java 存根):

Delphi and Android services

Delphi and Android services (part 2)

【讨论】:

    【解决方案2】:

    如何解决这个问题?这个错误.. JIntent - 类

    #include<Androidapi.JNI.App.hpp> //JService
    #include<Androidapi.JNI.GraphicsContentViewText.hpp> //JIntent
    

    这是火猴

    【讨论】:

    • 这没有回答问题。
    猜你喜欢
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多