Xamarin中的IntentFilter给出了带有代码1的Java.exe的错误。
我试图了解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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在额外活动的属性中添加了“导出= false”,并且它起作用。
代码就是这样:
I added "Exported = false" to Attributes of my extra Activity and it worked.
the code will be like that: