2013-06-12 4 views
0

C Sharp (Xamarin 사용)를 사용하여 Android 응용 프로그램을 만들고 현재 다른 클래스의 메서드 인 FeedActivity.cs를 호출하려고합니다. 안드로이드에서 실행할 수 있도록 자 마린 자바로 C#을 컴파일하기 때문에정의가없고 확장 메서드가 없습니다.

"FeedActivity:PostPicture: Exception of type 'Java.Lang.RuntimeException' was thrown." 

그것은 자바 오류입니다 : 그것은 오히려 일반 오류가 발생. 다음과 같이

코드는 다음과 같습니다

#class from which I want to call the method from the FacebookActivity.cs class 
public class FeedActivity : BaseActivity 
    { 

#the method that actually starts the whole process 
private void PostPicture(pic picture, bool shareOnFacebook) 
    { 
     #posts the picture to my own app, no problem here 

     #try catch statement, this is where the error comes in 
     try 
      { 
       if (shareOnFacebook) SharePictureOnFacebook(picture); 
      } 
     catch (Exception ex) 
      { 
       LogManager.Error(this, ex, "FeedActivity:PostPicture: ", ex.Message); 
      } 
    } 

#method from which I want to call the method from the FacebookActivity.cs class 
private void SharePictureOnFacebook(pic picture) 
     { 
      FacebookActivity permissionAdder = new FacebookActivity(); 

      #this is the line that is giving me the error 
      permissionAdder.AddPermissions() 

      #some more code that isn't relevant 
     } 
    } 

#class that I want to use the method from 
public class FacebookActivity : BaseActivity 
    { 
     #method I want to call from FeedActivity.cs in the SharePictureOnFacebook method 
     public void AddPermissions() 
     { 
      Authorize(this, AdditionalPermissions); 
     } 
    } 

UPDATE :

내가 정적 메서드하게하지만 그 작동하려면 그것에 인스턴스를 전달해야 할 때 작동

. 정적 방법이 효과가있는 이유는 무엇입니까?

+0

거룩한 지옥 Xamarin은 정말 멋져 보입니다. 나는 그것이 존재했는지 전혀 몰랐다. 너는 그것을 좋아하니? – Jonesopolis

+1

예, 매우 완벽하며 기본적으로 필요한 모든 것이 있습니다. 잠시 동안 Android 용 Java를 사용한 후 약간의 변화가 있었으며 때로는 약간의 오류가 발생했지만 C#을 사용하고 iOS 용 코드를 재사용 할 수있는 절충안이 필요합니다. – clifgray

답변

0

게시 된 코드에 따르면 정상적으로 작동합니다. 그러나 다른 네임 스페이스에서 같은 클래스 이름을 사용하면 전에 한 번 실행했습니다.

+0

음, 거기에는 아무런 충돌이 없습니다. 그것은 Xamarin – clifgray

+0

특정 뭔가 있어야합니다 정적 메서드를 사용하여 실제로 작동하지 않는 인스턴스를 필요로하기 때문에 필요한 이유가 작동 할 것이라고? – clifgray

+0

인스턴스와 함께 호출하기 때문에 어떤 이유로 든 생각할 수 없습니다. 인스턴스가 유형으로 읽히지 않는 한? –

관련 문제