我最終會在筆記文檔中寫入一些自定義數據。但在此之前,我想知道它是如何工作的,所以我從IBM知識中心複製/粘貼了關於兩個分離代理中的replace/getItemValueCustomData的示例。運行IBM代碼示例時出現ClassNotFoundException
問題是,當我嘗試讀取自定義數據,讀取代理拋出該異常:
java.lang.ClassNotFoundException: customData.IntIntString
at java.lang.Class.forName(Class.java:291)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:619)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1609)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1768)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:364)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
下面是代碼:
寫劑:
import customData.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
IntIntString iis = new IntIntString();
iis.setData(1, 2, "String1");
Document doc = agentContext.getDocumentContext();
doc.replaceItemValueCustomData("IntIntStringItem", "IntIntStringType", iis);
doc.save();
} catch (Exception e) {
e.printStackTrace();
}
}
閱讀代理:
import intIntString.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
if (doc.hasItem("IntIntStringItem")) {
IntIntString iis = (IntIntString) doc.getItemValueCustomData("IntIntStringItem", "IntIntStringType");
iis.show();
} else {
System.out.println("No item IntIntStringItem in document");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
IntIntString類:
package customData;
import java.io.Serializable;
public class IntIntString implements Serializable {
private static final long serialVersionUID = 6875473472063311349L;
private int int1;
private int int2;
private String string1;
public void setData(int i1, int i2, String s1) {
int1 = i1;
int2 = i2;
string1 = s1;
}
public void show() {
System.out.println("Int1 = " + int1);
System.out.println("Int2 = " + int2);
System.out.println("String1 = " + string1);
}
}
字節wrotes由代理:
. I n t I n t S t r i n g T y p e . . .
10 49 6E 74 49 6E 74 53 74 72 69 6E 67 54 79 70 65 AC ED 00
. s r . . c u s t o m D a t a . I n t I
05 73 72 00 17 63 75 73 74 6F 6D 44 61 74 61 2E 49 6E 74 49
n t S t r i n g _ j . . . . . . . . . I
6E 74 53 74 72 69 6E 67 5F 6A 96 B1 EC F4 8D F5 02 00 03 49
. . i n t 1 I . . i n t 2 L . . s t r i
00 04 69 6E 74 31 49 00 04 69 6E 74 32 4C 00 07 73 74 72 69
n g 1 t . . L j a v a/l a n g/S t r
6E 67 31 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72
i n g ; x p . . . . . . . . t . . S t r
69 6E 67 3B 78 70 00 00 00 01 00 00 00 02 74 00 07 53 74 72
i n g 1
69 6E 67 31
難道我錯過的東西或者是IBM喝醉了嗎?
鏈接到示例:replaceItemValueCustomData method,getItemValueCustomData method。
編輯:試圖在「代理」類來定義「IntIntString」類,但沒有工作,也沒有把類的.jar和導入。
編輯2:正如評論中所建議的,我試圖在代理中聲明類爲公共類。出於某種原因,當我嘗試過我必須在代理中實現Serializable時,我所做的是。仍然有同樣的例外。
然後我試圖在「customData」包中聲明它在一個單獨的文件中公開(因爲公共類需要它們自己的文件),但那也不起作用。
還嘗試讀取文檔以讀取模式打開時的字段。我得到的異常,並刪除領域(見從文件屬性):
NotesException: Supplied Data type name does not match stored CustomData type
at lotus.domino.local.Document.NgetItemValueCustomData(Native Method)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
接縫,該字段不讀/寫正確,數據類型應該匹配。
代碼已更新。
問題不清楚。問題是什麼?你在做什麼來解決它,你卡在哪裏? –
正如我在問題的第五行所說的那樣,問題在於IBM提供的代碼示例拋出異常。 –
這意味着「IntIntString」類未定義/找到。我不知道「IBM喝醉了」,但是您應該直接將該類導入到您的項目中,或者IBM有一個關於所有這些類的jar文件,您可以導入它。我認爲你應該看看谷歌的「IntIntString.class」搜索。 – pilkington