GideonLeGrange / mikrotik-java

A Java client implementation for the Mikrotik RouterOS API.
Apache License 2.0
176 stars 100 forks source link

Android Application has stopped #31

Closed AmrSubZero closed 8 years ago

AmrSubZero commented 8 years ago
Developing an android application testing the connection to the RouterOS using this API

Added the Maven compile code to the build.gradle in my android app :

compile 'me.legrange:mikrotik:2.2'

Imported the Class of the API :

import me.legrange.mikrotik.ApiConnection;
import me.legrange.mikrotik.MikrotikApiException;

And here's my code in the MainActivity :

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            ApiConnection.connect("192.168.1.2");
        } catch (MikrotikApiException e) {
            e.printStackTrace();
        }
    }
}
As we see it's very simple, nothing complicated just trying to connect

The problem is when i test the app it's crashing and saying

Unfortunetly App has stopped

Note : i'm testing the App live on my smartphone not in the Android studio AVD machine
Note : I'm asking for internet access permession in the installation process

I assume i'm using the API the right way, so how to fix this problem?

Metori commented 8 years ago

After "Unfortunetely App has stopped" you will receive stack trace in LogCat. Did you read it?

GideonLeGrange commented 8 years ago

@AmrSubZero You seem to be instantiating the app correctly. I will need to see a stack trace to understand the problem. Can you get a stack trace?

GideonLeGrange commented 8 years ago

@AmrSubZero

Having thought about this some more, I speculate that the code is causing a Throwable or RuntimeException. I see you have a catch there with a printStackTrace(), so assuming you can get the output of a print, I suggest you change your code like this:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            ApiConnection.connect("192.168.1.2");
        } catch (MikrotikApiException e) {
            e.printStackTrace();
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

At least we'll then be able to pick up why the app is stopping. Please let me know, or if this issue is no longer relevant, please close the issue.