# How to debug Uno Classes

**URL:** <https://forums.fusetools.com/t/how-to-debug-uno-classes/3686>\
**Category:** How-to Discussions\
**Created:** [June 13, 2017, 1:05pm UTC](https://forums.fusetools.com/t/how-to-debug-uno-classes/3686 "2017-06-13T13:05:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammed\_Manssour](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/mohammed_manssour/32/658_2.png) [@Mohammed\_Manssour](https://forums.fusetools.com/u/Mohammed_Manssour)\
**Post date:** [June 13, 2017, 1:05pm UTC](https://forums.fusetools.com/t/how-to-debug-uno-classes/3686/1 "2017-06-13T13:05:38Z")

</div>

Hi

I’ve been trying to write a code to get phone’s native number using Foreign code, after i wrote the class the preview stopped completely so i guess there’s a problem in my class but simply i don’t know where.

So i have to ask a stupid question : **How to debug uno classes ?**

also do you think my class has any errors ?

```auto
using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Uno.Permissions;
using Uno.Threading;
using Uno.UX;

using Uno.Compiler.ExportTargetInterop;

[UXGlobalModule]
public class PhoneNumber : NativeModule
{
    static readonly PhoneNumber _instance;

    static string cachedPhoneNumber;

    public PhoneNumber(){
        if(_instance !=null) return;
        _instance = this;

        Resource.SetGlobalKey(_instance, "PhoneNumber");

        AddMember(new NativeProperty< string, object >("phoneNumber", phoneNumber));

        // async getUUID implementation
        AddMember(new NativePromise<string, string>("getLineNumber", AsyncPhoneNumber, null));
    }

    Future<string> AsyncPhoneNumber (object[] args)
    {
        return AsyncPhoneNumberImpl();
    }

    public static extern(!Android) Future<string> AsyncPhoneNumberImpl()
    {
        var p = new Promise<string>();
        p.Resolve(GetPhoneNumber());
        return p;
    }

    static extern(Android) Promise<string> _authorizePromise;

    public static extern(Android) Future<string> AsyncPhoneNumberImpl()
    {
        if (_authorizePromise == null)
        {
            _authorizePromise = new Promise<string>();
            Permissions.Request(Permissions.Android.READ_PHONE_STATE).Then(AuthorizeResolved, AuthorizeRejected);
        }
        return _authorizePromise;
    }

    private static extern(Android) void AuthorizeResolved(PlatformPermission permission)
    {
        if (cachedPhoneNumber == null) {
            cachedPhoneNumber = GetPhoneNumber();
        }
        _authorizePromise.Resolve(cachedPhoneNumber);
    }

    private static extern(Android) void AuthorizeRejected(Exception reason)
    {
        _authorizePromise.Reject(reason);
    }

    public static extern(!Android) string phoneNumber() {
        if (cachedPhoneNumber == null) {
            cachedPhoneNumber = GetPhoneNumber();
        }
        return cachedPhoneNumber;
    }

    public static extern(Android) string phoneNumber() {
        if (cachedPhoneNumber == null) {
            debug_log("Permissions not granted. Consider using Device.getUUID() instead.");
            return "";
        }
        return cachedPhoneNumber;
    }

    [Foreign(Language.Java)]
    [Require("AndroidManifest.RootElement", "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>")]
    static extern(Android) string GetPhoneNumber()
    @{
        final android.app.Activity context = com.fuse.Activity.getRootActivity();
        android.telephony.TelephonyManager tMgr = (android.telephony.TelephonyManager)context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return mPhoneNumber;
    @}

    static extern(!Android) string GetPhoneNumber()
    {
        debug_log("Toast not supported on this platform.");
    }
}

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![kusma](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kusma/32/595_2.png) [@kusma](https://forums.fusetools.com/u/kusma)\
**Post date:** [June 13, 2017, 2:42pm UTC](https://forums.fusetools.com/t/how-to-debug-uno-classes/3686/2 "2017-06-13T14:42:57Z")

</div>

`uno build -tandroid -d <YourProject.unoproj>`, and Android Studio should start. You can debug from there. The code will look a bit different, as it’s C++ code generated from the Uno code, but it’s usually quite manageable.
