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 :
내가 정적 메서드하게하지만 그 작동하려면 그것에 인스턴스를 전달해야 할 때 작동. 정적 방법이 효과가있는 이유는 무엇입니까?
거룩한 지옥 Xamarin은 정말 멋져 보입니다. 나는 그것이 존재했는지 전혀 몰랐다. 너는 그것을 좋아하니? – Jonesopolis
예, 매우 완벽하며 기본적으로 필요한 모든 것이 있습니다. 잠시 동안 Android 용 Java를 사용한 후 약간의 변화가 있었으며 때로는 약간의 오류가 발생했지만 C#을 사용하고 iOS 용 코드를 재사용 할 수있는 절충안이 필요합니다. – clifgray