我正在做一个简单的示例,将我的qt android项目与java文件链接。但是,在遵循所有上述更改之后,在线QT无法找到Java文件。我已将Java文件保存在根目录中。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
ui->setupUi(this);
NetworkConnectionObject = new NetworkConnection();
QAndroidJniObject::callStaticMethod<jint>
("OrientationChanger" // class name
, "change" // method name
, "(I)I" // signature
, 1); // setScreenOrientation(1); }
Java文件是
public class OrientationChanger
{
public static int change(int n)
{
switch(n)
{
case 0:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case 1:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
}
}
}
专业文件为
QT += core gui network androidextras
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AndroisShop
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp \
secondscreen.cpp \
networkconnection.cpp \
shoppingcardconnection.cpp
HEADERS += \
mainwindow.h \
secondscreen.h \
networkconnection.h \
shoppingcardconnection.h
FORMS += \
mainwindow.ui \
secondscreen.ui
CONFIG += mobility
MOBILITY =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
DISTFILES += \
OrientationChanger.java
看起来问题出在项目文件中的Java文件链接上,但不知道问题出在哪里。
错误是
W/System.err(16145): java.lang.ClassNotFoundException: Didn't find class "OrientationChanger" on path: