hello

I'm beginner on c#. I'm getting this error:

System.NullReferenceException was unhandled

and my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GittiGidiyor;
using GittiGidiyor.City;

namespace ConsoleApplication1
{ 
    class Program
    {
        static void Main(string[] args)
        {
            [B]CityService cityservice = ServiceProvider.getCityService();[/B]
            cityServiceResponse response = cityservice.getCities(1, 3, "", "tr");


            if (response != null && response.ackCode.ToString().Equals("success"))
            {
                cityType[] city = response.cities;
                foreach (cityType cities in city)
                {

                    Console.WriteLine("citycode :" + cities.trCode + " / cityname :" + cities.cityName);
                }
            }
            else
            {
                Console.WriteLine("errorid :" + response.error.errorId);
                Console.WriteLine("errorcode :" + response.error.errorCode);
                Console.WriteLine("errormessage :" + response.error.message);
            }
        }              
        }
    }

I've bolded line about getting error
I'll be glad if someone help me
thanks

Recommended Answers

All 2 Replies

Given I have no idea what GittiGidiyor is. I'll take a guess based on my own experiences. ServiceProvider.getCityService(); is not being defined/set and is not static. If it was static you could do that, if it isn't you'll have to define it as a ServiceProvider first:

ServiceProvider sProvider = new ServiceProvider();
CityService cityservice = sProvider.getCityService();

If that doesn't work. Type out (assuming you're using VC#) GittiGidiyor. and see what options it has available to use.

Yes doens't work. Thats mean not static.
I'll type gittigidiyor.
Thank you for advice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.