2

restsharp를 통해 사용자의 데이터를 서버로 전송하려고합니다. 아래는 내가 사용한 코드입니다. "이름 'InitializeComponent'가 현재 컨텍스트에 존재하지 않는다는 오류가 발생했습니다."사용자와 서버간에 데이터 전달하기

어떻게 디버깅합니까? 논리적 인 오류가 있습니까?

'using System; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using RestSharp; 
using Newtonsoft.Json.Linq; 
using Newtonsoft.Json; 
using System.Text.RegularExpressions; 
using System.Collections.Generic; 
using System.Linq; 


namespace Miser_sApp 
{ 
    public class RestSharp 
    { 
     public partial class SearchResults : PhoneApplicationPage 
     { 
      public static float _latitude, _longitude; 
      public static DateTime _date, _time; 
      public static string _name, _details; 
      public static int _number, _amount, _uid; 
      RestClient client; 
      RestRequest request; 

      int index; 
      connect Connect; 
      public SearchResults() 
      { 
       InitializeComponent(); 
       load(); 

      } 
      private RestClient InitializeX() 
      { 
       var client = new RestClient("//localhost" + Panorama1.username1 +    "&pro_type=" + Panorama1.number1 + "&pro_name=" + Panorama1.details1 + "&lat=" + Panorama1.lat1 + "&lon=" + Panorama1.lon1); 
       return client; 
       // request = new RestRequest(Method.GET); 
      } 
      public void load() 
      { 
       client = InitializeX(); 
       //MessageBox.Show("InternalInitialize Done"); 
       request = new RestRequest(Method.POST); 

       client.ExecuteAsync<connect>(request, (response) => 
       { 
        // MessageBox.Show(response.Data.ToString()); 
        Connect = response.Data; 
        if (response.Data == null || Connect.last == null || Connect == null) 
        { 
         MessageBox.Show("NO ITEMS FOUND"); 
         NavigationService.Navigate(new Uri("/Personal.xaml", UriKind.Relative)); 

        } 
        // name1.Items.Add(rootObject3.Details[0].ProductName); 
        //results.Items.Clear(); 
        //int i = 0; 
        else 
         foreach (var row3 in Connect.last) 
         { 
          results.Items.Add("NAME-" + row3.Name + '\n' + "Details-" + row3.Details + '\n' + "Date-" + row3.Date + '\n' + "Amount-" + row3.Amount + '\n' + "userId-" + row3.Uid + '\n' + "---------------------------------------------------------------"); 
         } 
       }); 

      } 




      private void Button_Click(object sender, RoutedEventArgs e) 
      { 

       Konnect d = Connect.last[index]; 
       _name = d.Name; 
       _date = d.Date; 
       _time = d.Time; 
       _uid = d.Uid; 
       _amount = d.Amount; 
       _details = d.Details; 
       _latitude = d.Latitude; 
       _longitude = d.Longitude; 

       NavigationService.Navigate(new Uri("/Panaroma1.xaml", UriKind.Relative)); 


      } 

      private void results_SelectionChanged(object sender, SelectionChangedEventArgs e) 
      { 
       index = results.SelectedIndex; 
      } 

     } 
     public class Konnect 
     { 
      public string Name { get; set; } 
      public DateTime Date { get; set; } 
      public DateTime Time { get; set; } 
      public int Uid { get; set; } 
      public String Details { get; set; } 
      public int Amount { get; set; } 
      public float Latitude { get; set; } 
      public float Longitude { get; set; } 
     } 

     public class connect 
     { 
      public List<Konnect> last { get; set; } 
     } 

    } 
} 

답변

0

즉, InitializeComponent(); 메서드가 존재하지 않습니다. 아래 코드를 참조하십시오. 이는 참조 문제 일 수 있습니다. 디자이너 지원에 필요한대로 디자이너 파일에 문제가 있음을 의미 할 수도 있습니다. 당신은 당신이 디버거를 실행할 때 그 방법으로 나아갈 수 있습니다. 또한 오류가 발생합니까? 실행 시간 오류입니까 아니면 컴파일하려고 할 때 발생합니까? 컴파일 오류가 발생하면 메서드가 존재하지 않으며 해당 메서드에서 해당 메서드를 만들거나 해당 메서드의 참조를 제거해야합니다.

public SearchResults() 
{ 
    InitializeComponent(); 
    load(); 

} 

편집 : 귀하는 아마도 designer.cs 파일에서이 부분을 누락

. 이것은 win form 응용 프로그램을 기반으로합니다. 상속을 시도하는 클래스에 대해이 메소드가 어디에 위치하는지 연구해야합니다. 즉 PhoneApplicationPage 클래스

#region Windows Form Designer generated code 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     this.components = new System.ComponentModel.Container(); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.Text = "Form1"; 
    } 
    #endregion 

방금 ​​새 앱을 만들었으며 자동으로 생성되었습니다. 당신은 그것을 삭제해야합니다.

+0

컴파일하는 동안 오류가 발생합니다. 방법이 존재하지 않는다는 것은 무슨 뜻입니까? 이 클래스는 새 클래스를 만들 때 Visual Studio에서 만들어집니다. – nik

+0

이것은 .designer.cs 파일 또는 무엇인가에 문제가 있음을 의미합니다. 귀하의 오른쪽 비주얼 스튜디오가 당신을 위해 그 방법을 생성합니다. 내가 제안 할 수있는 것은 새로운 응용 프로그램을 만들고 .designer.cs 파일 아래에 한 가지 방법을 제시하는 것입니다. 위의 편집을보십시오. –

+0

designer.cs 파일은 어디에 있습니까? – nik

관련 문제