开发者

I'm trying to make mono android simple "hello world" but I don't see "hello world" in the emulator why?

I uninstalled the android ask and reinstalled it to c:\androidSdktools without spaces. So now the emulator works I can see the emulator.

But tried some codes of the "hello world" text and when I'm running the application and running the emulator I see the android emulator but I can't see wnyhere "hello world". I'm not sure if I didn't do anything good or maybe it's because I'm still getting error when exit the emulator and stop debugging im getting the error say: deployment erros. If I say "yes" continues then he ask me to rebuild/build my solution before I run/debug it I did but it didn't solve this error.

I don't know if this error have anything to do with the fact that I don't see any "hello world" text in the android emulator.

I tried to m开发者_如何学Goake this code now:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MonoAndroidApplication1
{
    [Activity(Label = "MonoAndroidApplication1", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }
}

I have visual studio c# 2010 pro.

I tried it this is automatic code created when I selected to make new android mono application.

But I didnt see anything any text in the emulator. I tried to add to this code as:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MonoAndroidApplication1
{
    [Activity(Label = "MonoAndroidApplication1", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        int count = 1;
        TextView tv;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            tv = new TextView(this);
            tv.Text = "hello world";
            SetContentView(tv);
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }
}

And again nothing I didn't see in the emulator when running it any text "hello world" And still getting this deployment errors when exiting the emulator and stop debugging/running the application. The emulator is now running fine but still getting this errors when exiting.

And why I dont see the text "hello world" on the emulator ?

Thanks.


Once you change the layout by calling SetContentView the second time, there is no longer a Button in the layout so your FindViewById is returning null. Then you are trying to set the event on a null reference.

Look at how to read the error log so you can find errors:

http://android.xamarin.com/Documentation/Guides/Android_Debug_Log


It may also be that you haven't chosen the running emulator instance as I explained here. Doing so together with the installation instructions and the Hello World tutorial for Monodroid worked fine for me.


Probably you are not attaching the emulator in the right way

Instead of pressing F5 to let visual studio auto-attach the emulator

try:

click button Star Android Emulator Manager (it's at the right of the combobox that says prompt for device)

after the emulator, it will apper in the combobox, if it doesn't apper you have to exit from VS and then open it again (I will appear, as long as you have your emulator open)

Select it from the combobox, and then press F5

Done


What version of Java did you install? I installed on my second computer Java 7 and found out that Monodroid does not support Java 7 and that was the reason why I only saw the emulator and no "hello world" application.

I guess last week or so when I did it on my other computer they had not released Java 7.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜