小编pro*_*eve的帖子

错过了一步?什么需要填写loadLibrary()的参数

这些是我从java程序调用本机函数时所遵循的不完整步骤.

  1. 写了一个java程序然后编译成.class文件
  2. 从命令javah - jni我生成了一个与文件同名的头.class文件.
  3. 之后,我打开了一个Microsoft Visual C++ Express,启动了一个新项目并将我的应用程序类型设置为dll.

这是调用本机c方法的java程序.

class HelloWorld {

private native void print();

public static void main( String args[] ) {
  new HelloWorld().print();
}

static {
  System.loadLibrary("??"); // what should i write here ?
}
Run Code Online (Sandbox Code Playgroud)

}

这是c程序

#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL 
Java_HelloWorld_print( JNIEnv *env , jobject obj) {
  printf("Hello World!\n");
  return;
}
Run Code Online (Sandbox Code Playgroud)

我将项目名称保留为jni tester,并且c文件名为HelloWorld.c

在语句System.loadLibrary(??)中参数中库的名称应该是什么?(或者在填写loadLibrary的参数之前,我是否缺少任何步骤) …

c java java-native-interface

3
推荐指数
1
解决办法
102
查看次数

为什么标签的颜色不会改变?

页面加载后,标签的颜色(即"输入你的名字")应改为红色.但标签的颜色保持不变.为什么会这样?

脚本

window.onload = startScript;

function startScript() {
if( document.getElementById("text_field").value === "me") {
    var allTags = document.getElementsByTagName("label");
    allTags.className = "inserter";
}
}
Run Code Online (Sandbox Code Playgroud)

HTML

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title>
<script type="text/javascript" src="inserter.js">
</script>
<style type="text/css">
@import url("inserter.css");
</style>
</head>

<body bgcolor="#99FFFF">
<form>
<label>Enter your name<input type="text" id="text_field" value="me" />
</label>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

CSS

@charset "utf-8";
/* CSS Document */

.inserter {
color:#F00;
}
Run Code Online (Sandbox Code Playgroud)

现在,由于该值等于me类名,因此"inserter"会动态插入到label元素中,颜色应该显示为红色.

为什么不这样呢?

html javascript css forms

2
推荐指数
1
解决办法
161
查看次数

toDateString 有什么问题

下面是一个脚本+HTML,告诉用户他上次访问的页面。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cookie</title>
<script type="text/javascript">
window.onload = initLastVisit;

function initLastVisit() {
var now = new Date();
var last = new Date();
now.setMonth(now.getMonth()+6);
document.cookie = "lastVisit=" + last.toDateString() + ";path=/;expires=" + now.toGMTString();
document.getElementById("lastVisitedOn").innerHTML = document.cookie.split("=")[1];
}
</script>
</head>

<body>
<form>
<label>Enter your name&nbsp;&nbsp;<input type="text" id="name_field" /></label> <br/>
</form>
<h1 id="lastVisitedOn"></h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

上述脚本中设置cookie的语句是:document.cookie = "lastVisit=" + last.toDateString() + ";path=/;expires=" + now.toGMTString();。如果在这里我用浏览器中的过期时间替换为now.toGMTString()关闭浏览器时过期”。这是为什么 ?没关系。预计到期日期为 2012 年 3 月。now.toDateString()toGMTString

javascript cookies

2
推荐指数
1
解决办法
8850
查看次数

尝试在显式初始化期间创建函数副本时出错

我无法理解我在模板类程序中遇到的错误.

#include <iostream>
#include<string>

using namespace std;

template <class dataType> class myClass {
public:
void function();
};

template<> class myClass<int> {
public:
void expli_function();
};

template <class dataType> void myClass<dataType>::function() {
cout << "Not an explicit function !" << endl;
}

template <class int> void myClass<int>::expli_function() { //<-- while pointing towards errors compiler points here
cout << "Explicit function !" << endl;
}

int main() {
myClass<string> ob1;
myClass<int> ob2;
ob1.function();
ob2.expli_function();
} 
Run Code Online (Sandbox Code Playgroud)

错误是:

tester_1.cpp(20): error C2332: 'class' : …
Run Code Online (Sandbox Code Playgroud)

c++ generics templates

2
推荐指数
1
解决办法
180
查看次数

尝试生成存根文件时出错

当我尝试使用rmic RemoteMethodImpl 以下方法生成存根文件时:出现以下错误:

error: File .\RemoteMethodImpl.class does not contain type RemoteMethodImpl as expected, but type InterfaceImplementation.RemoteMethodImpl. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
error: Class RemoteMethodImpl not found.
2 errors
Run Code Online (Sandbox Code Playgroud)

这是什么错误?为什么我得到这个?

应@Shashank Kadne 的要求

package InterfaceImplementation;
import Interfaces.RemoteMethodIntf;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import Design.Main_Design_Client;
/**
 *
 * @author program-o-steve
 */
 public class RemoteMethodImpl extends UnicastRemoteObject implements RemoteMethodIntf{
  public RemoteMethodImpl() throws Exception{}   

@Override
public void send(String IP,String Message) throws RemoteException …
Run Code Online (Sandbox Code Playgroud)

java rmi stub

2
推荐指数
1
解决办法
2723
查看次数

这个程序有什么问题?

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main() {
    string x;
    getline(cin,x);
    ofstream o("f:/demo.txt");
    o.write( (char*)&x , sizeof(x) );
}
Run Code Online (Sandbox Code Playgroud)

我得到了意想不到的输出.我没有得到我在字符串函数中写的东西.为什么是这样 ?请解释 .

就像我写的时候steve pro我得到8/ steve pro ÌÌÌÌÌÌ ÌÌÌÌ文件中的输出

我希望输出是史蒂夫亲

c++ io visual-c++

1
推荐指数
1
解决办法
185
查看次数

在比较if语句中的3个参数时,无法理解第一个代码的输出

这是一个小代码,可以一次比较3个变量.我比较了两个代码.

第一

#include <iostream>

int main() {
if( 8 > 7 > 6) std::cout << "true";
else std::cout << "false";
std::cout << "\n";
std::cout << (8 < 9); 
std::cout << "\n";
system("pause");
}
// output :
/* false
 * 1
 */
Run Code Online (Sandbox Code Playgroud)

第二

#include <iostream>

int main() {
if( 8 > (7 > 6) ) std::cout << "true"; // with brackets
else std::cout << "false";
std::cout << "\n";
std::cout << (8 < 9); 
std::cout << "\n";
system("pause");
}
// output : …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement

1
推荐指数
1
解决办法
127
查看次数

初始化JNI_CreateJavaVM的第三个参数

该方法JNI_CreateJavaVM的第三个参数将第三个参数作为JavaVMInitArgs结构.

typedef struct JavaVMInitArgs { 
                     jint version; 
                     jint nOptions; 
                     JavaVMOption *options; 
                     jboolean ignoreUnrecognized; 
                 } JavaVMInitArgs;
Run Code Online (Sandbox Code Playgroud)

我如何初始化这个?我无法这样做.

JNI_CreateJavaVM的原型:jint JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *vm_args);

我如何初始化vm_args?

java java-native-interface

1
推荐指数
1
解决办法
3333
查看次数

如何在链表的节点之间移动?

这是一段试图构建链表的代码.

struct node {
    char name[20];
    int age;
    int height;
    node* next; // Pointer to the next node
};
node* startPTR = NULL;

void addNode_AT_END() {
    node *temp1;
    node *temp2;

    temp1 = new node;  

    cout << "Enter the name : ";
    cin  >> temp1->name;
    cout << endl << "Enter the age : ";
    cin  >> temp1->age;
    cout << endl << "Enter height : ";
    cin  >> temp1->height;

    temp1->next = NULL;

    if( startPTR == NULL) {
       startPTR = temp1; 
    }  else …
Run Code Online (Sandbox Code Playgroud)

c++ pointers linked-list list

0
推荐指数
1
解决办法
8281
查看次数

在复制构造函数中表示什么?

#include <iostream>

using namespace std;

class tester {
public:
int a;
tester( int x ) {
    a = x;
}

tester( tester &t ) {
    cout << t.a;
}
};

int main() {
 tester t(10);
 tester t_1(t);
}

output : 10
Run Code Online (Sandbox Code Playgroud)

在复制构造函数的定义中t引用了什么?从main传入t参数时t_1,它的地址被存储在&t复制构造函数的表单中.什么t.a意思?

c++ constructor copy-constructor

0
推荐指数
1
解决办法
159
查看次数

该程序没有提供所需的输出.错误的FIFO实现?

这是一个使用的FIFO程序linked list.该程序没有提供所需的输出,但会生成一个长循环,该循环在某个时间后停止并且有一条消息表明程序已停止工作.问题是什么 ?

#include <iostream>
using namespace std;

struct node {
      int data;
      struct node* previous; // This pointer keeps track of the address of the previous node
};

struct queue {
      node* first;
      node* last;
};

node* dataNode_P_A; 

bool loop = true;

struct node* enterData();
struct node* enter_N_Data();
void displayQueue();

int main() {
    struct node* dataNode= enterData();

    while( loop ) {
        cout << "Want to enqueue ? Press y/n : ";
        char ans;
        cin >> ans;
        if( …
Run Code Online (Sandbox Code Playgroud)

c++ queue fifo visual-c++ data-structures

-2
推荐指数
1
解决办法
181
查看次数