windows app中的program.cs文件问题 [英] Issue with program.cs file in windows app

查看:131
本文介绍了windows app中的program.cs文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我开发了一个Windows应用程序。我在代码中使用了后台工作程序。

当我在工作时我的应用程序突然在program.cs文件中抛出错误

空引用异常未处理

对象引用未设置为对象的实例。



在application.run();如何解决这个错误。





 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Windows.Forms;


命名空间 AISQBTool
{
静态 class 程序
{
///
/// 应用程序的主要入口点。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Login());
}
}
}

解决方案


抓住异常,看看哪里是实际发生的问题。



 [STAThread] 
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new Login());
}
Catch(例外情况)
{
Console.Out.WriteLine(ex.StackTrace);
}
}





stcktrace会告诉你代码失败的文件在哪一行。 />


问候

Jegan


我们在没有看到任何代码的情况下无法快速到达。请尝试以下方法......



1.创建应用程序

2.添加登录表单 - 使用您遇到问题的程序中的登录表单

3.将所需的所有控件添加到该表单但不添加任何其他代码

4.运行新程序并确认它没有抛出异常

5.一次一位地添加原始登录表单中的任何其他代码

6.添加每个代码段后运行程序确认它不会抛出异常

- 如果确实抛出异常那么你确切地知道哪一段代码导致问题。

7.如果没有抛出异常那么你需要比较 Form1 .Designer.cs 来自两个项目的文件(也可能是Form1.cs) - 当你发现差异时,你就会知道问题在哪里,应该能够解决问题


的cHEC k数据库的类文件,检查Varaible的变量拼写和数据类型及其各自的属性。



或者另一种方式是,

你必须将null值传递给NOT NULL的数据库。


Hello,

I developed an windows application.I used an background worker process in my code.
When i was working on my application suddenly it throws an error in program.cs file
Null reference exception was unhandled
Object reference not set to an instance of an object.

in application.run(); line how to fix this error.

[Edit- OPs code from his comment]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;


namespace AISQBTool
{
    static class Program
    {
        ///
        /// The main entry point for the application.
        ///
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());
        }
    }
}

解决方案

Hi Catch the exception and see where is the issue actually occured.

[STAThread] 
static void Main() 
{ 
    try
    {
        Application.EnableVisualStyles(); 
        Application.SetCompatibleTextRenderingDefault(false); 
        Application.Run(new Login()); 
    }
    Catch (Exception ex)
    {
        Console.Out.WriteLine(ex.StackTrace);
    }
}



The stcktrace will tell you at which line in which file the code failed.

Regards
Jegan


We''re getting no where fast here without seeing any code. Try the following...

1. Create a new application
2. Add a Login form - do not use the Login form from the program you''re having the problem with
3. Add all of the controls you need onto that form but do not add any other code
4. Run the new program and confirm that it does not throw the exception
5. Add any other code you have in the original Login form one bit at a time
6. After adding each code segment run the program to confirm it does not throw the exception
- If it does throw an exception then you know exactly which piece of code is causing the problem.
7. If it doesn''t throw an exception then you need to compare the Form1.Designer.cs files from both projects (and possibly Form1.cs also) - when you find the differences then you will know where the problem lies and should be able to solve the problem


Check Class file of your database, Check variable Spellings and Datatype of Varaible with its respective property.

Or another way is,
you must be passing null values into the database which is NOT NULL.


这篇关于windows app中的program.cs文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆