Xamarin中的IntentFilter给出了带有代码1的Java.exe的错误。

发布于 2025-02-13 18:51:26 字数 2384 浏览 2 评论 0原文

我试图了解Xamarin中的动作如何起作用,并试图将其中一些添加到我的活动中。它通过错误“ Java.exe用代码1退出”而构建。我发现相同的代码在我的主要启动器活动中起作用,但是当我将其添加到其他活动中时,它不会编译。

我试图搜索答案,但是这个问题没有话题,所以我决定在这里写信寻求帮助。

这是我第一次询问btw ._。

此代码构建

namespace XamarinLearningField
{
    [Activity(Label = "SomeApp", Theme = "@style/AppTheme", MainLauncher = true)]
    [IntentFilter(new[] { Intent.ActionView },
        Categories = new[] { Intent.CategorySampleCode, "my.custom.category" })]
    public class MainActivity : AppCompatActivity, Android.Views.View.IOnClickListener
    {
        TextView tvName;
        Button btnName;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            tvName = (TextView)FindViewById(Resource.Id.tvName);
            btnName = (Button)FindViewById(Resource.Id.btnName);
            btnName.SetOnClickListener(this);

            Button btnTime = (Button)FindViewById(Resource.Id.btnTime);
            Button btnDate = (Button)FindViewById(Resource.Id.btnDate);

            btnTime.SetOnClickListener(this);
            btnDate.SetOnClickListener(this);
        }
}

不是

{
    [Activity(Label = "Data/Time info", MainLauncher = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Info_ActivityLayout);

          
            Intent intent = this.Intent;
            String action = intent.Action;
            String format = "", textInfo = "";

            if (action.Equals("en.startandroid.intent.action.showtime"))
            {
                format = "HH:mm:ss";
                textInfo = "Time: ";
            }
            else if (action.Equals("en.startandroid.intent.action.showdate"))
            {
                format = "dd.MM.yyyy";
                textInfo = "Date: ";
            }

            ...
}

I'm trying to understand how actions in xamarin work and i tried to add some of them to my activity. It builds with error "java.exe exited with code 1". I found that the same code works in my main launcher activity, but it doesn't compile when I'm adding it to the other activities.

I tried to search for answer, but there is no topic with that question, so i decide to write here for help.

This is my first time questioning btw ._.

this code builds

namespace XamarinLearningField
{
    [Activity(Label = "SomeApp", Theme = "@style/AppTheme", MainLauncher = true)]
    [IntentFilter(new[] { Intent.ActionView },
        Categories = new[] { Intent.CategorySampleCode, "my.custom.category" })]
    public class MainActivity : AppCompatActivity, Android.Views.View.IOnClickListener
    {
        TextView tvName;
        Button btnName;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            tvName = (TextView)FindViewById(Resource.Id.tvName);
            btnName = (Button)FindViewById(Resource.Id.btnName);
            btnName.SetOnClickListener(this);

            Button btnTime = (Button)FindViewById(Resource.Id.btnTime);
            Button btnDate = (Button)FindViewById(Resource.Id.btnDate);

            btnTime.SetOnClickListener(this);
            btnDate.SetOnClickListener(this);
        }
}

this not

{
    [Activity(Label = "Data/Time info", MainLauncher = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Info_ActivityLayout);

          
            Intent intent = this.Intent;
            String action = intent.Action;
            String format = "", textInfo = "";

            if (action.Equals("en.startandroid.intent.action.showtime"))
            {
                format = "HH:mm:ss";
                textInfo = "Time: ";
            }
            else if (action.Equals("en.startandroid.intent.action.showdate"))
            {
                format = "dd.MM.yyyy";
                textInfo = "Date: ";
            }

            ...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2025-02-20 18:51:27

我在额外活动的属性中添加了“导出= false”,并且它起作用。

代码就是这样:

 [Activity(Label = "Data/Time info", Exported = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
       ...

I added "Exported = false" to Attributes of my extra Activity and it worked.

the code will be like that:

 [Activity(Label = "Data/Time info", Exported = false)]
    [IntentFilter(new[] { "en.startandroid.intent.action.showtime","en.startandroid.intent.action.showdate" },
        Categories = new[] { Intent.CategoryDefault })]
    public class InfoActivity : AppCompatActivity
    {
       ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文