 |
|
NullReferenceException was unhanddle : Object reference not set to an instance of an object. คืออะไรครับ เขียนติดต่อ Fingerprint USB |
|
 |
|
|
 |
 |
|
ผมลองเขียนโปรแกรมง่าย ๆ ติดต่อกับ Fingerprint โค๊ดดังนี้
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (axZKFPEngX1.InitEngine() == 0)
{
label1.Text = "เชื่อมแต่ได้";
//MessageBox.Show("เชื่อมต่อได้","เริ่มระบบ",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}else {
label1.Text = "เชื่อมแต่ผิดพลาด";
//MessageBox.Show("ไม่สามารถเชื่อมต่อได้","เริ่มระบบ",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
}
}
}
ผมได้ Add reference ตัวไฟล์ dll เรียบรอ้ยแล้ว ประกอบด้วย AxInterop.ZKFPEngXControl กับ Interop.ZKFPEngXControl
ประกาศ property ใน Form1.Designer.cs แล้ว
Form1.Designer.cs
private AxZKFPEngXControl.AxZKFPEngX axZKFPEngX1;
พอผมรัน มันไม่ขึ้น error แต่ขึ้น warning ดังกล่าว
ลอง publish ออกมา มันก็ขั้นคล้าย ๆ กันว่า Object reference not set to an instance of an object
รบกวนด้วยครับ ขอบคุณครับ
Tag : .NET, Win (Windows App), C#, VS 2008 (.NET 3.x)
|
ประวัติการแก้ไข 2011-08-30 11:54:24
|
 |
 |
 |
 |
Date :
2011-08-30 11:53:04 |
By :
bankjetdo |
View :
6780 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้า Add reference ผ่านแล้ว Error ไม่น่าจะใช่แบบนี้น่ครับ ลอง Debug ดูครับ 
|
 |
 |
 |
 |
Date :
2011-08-30 12:35:34 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณยังไม่ได้ new class เลยครับ 
|
 |
 |
 |
 |
Date :
2011-08-30 12:53:28 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องไป new class ตรงไหนครับ ยกตัวอย่างได้ไหมครับ
|
 |
 |
 |
 |
Date :
2011-08-30 13:37:24 |
By :
bankjetdo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
axZKFPEngX1 = new axZKFPEngX1();
|
 |
 |
 |
 |
Date :
2011-08-30 13:41:21 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้แก้ได้แล้วครับ แต่มันขึ้นอันใหม่
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.
|
 |
 |
 |
 |
Date :
2011-08-30 14:24:09 |
By :
bankjetdo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนิว Class อาจจะมี Contructor ที่รับ Parameters อีก Contructor หรือเปล่า
axZKFPEngX1 = new axZKFPEngX1();
axZKFPEngX1 = new axZKFPEngX1(Parameter, Parameter);
ปล. ไม่แน่ใจนะครับ
ขอโทษด้วยถ้าไม่ถูกต้อง
|
 |
 |
 |
 |
Date :
2011-08-30 15:54:36 |
By :
่ำVC#.Net |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|