I've been trying to use IndoorAtlas from their sdk docs also https://indooratlas.freshdesk.com/support/solutions/articles/36000051242-fetching-floor-plan-images-with-android

But some variables are not initialized here and they are throwing null object reference exception.

My MainActivity.java

public class MainActivity extends AppCompatActivity {
    IALocationManager mIALocationManager;
    private IAResourceManager mResourceManager;
    private ImageView mFloorPlanImage;
    IATask<IAFloorPlan> mPendingAsyncResult = new IATask<IAFloorPlan>() {
        @Override
        public void cancel() {

        }

        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public IAResult<IAFloorPlan> get() {
            return null;
        }

        @Override
        public void setCallback(IAResultCallback<IAFloorPlan> iaResultCallback, @Nullable Looper looper) {

        }
    };
    private ImageView imageview;
    private IARegion.Listener mRegionListener = new IARegion.Listener() {
        @Override
        public void onEnterRegion(IARegion region) {
            if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
                fetchFloorPlan(region.getId());
            }
        }

        @Override
        public void onExitRegion(IARegion region) {
            // leaving a previously entered region
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mIALocationManager = IALocationManager.create(this);
        mResourceManager = new IAResourceManager.create(getApplicationContext());
        mIALocationManager.registerRegionListener(mRegionListener);
        imageview = findViewById(R.id.ImageView);
        fetchFloorPlan("78980b5a-4a9e-41ff-a949-809b5b77c258");
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
    private void handleFloorPlanChange(IAFloorPlan newFloorPlan) {
        Picasso.get().load(newFloorPlan.getUrl()).into(imageview);
    }
    private void fetchFloorPlan(String id) {
        // Cancel pending operation, if any
        if (mPendingAsyncResult != null && !mPendingAsyncResult.isCancelled()) {
            mPendingAsyncResult.cancel();
        }
        mPendingAsyncResult = mResourceManager.fetchFloorPlanWithId(id);
        if (mPendingAsyncResult != null) {
            mPendingAsyncResult.setCallback(new IAResultCallback<IAFloorPlan>() {
                @Override
                public void onResult(IAResult<IAFloorPlan> result) {
                    Log.d("Humza Yunas", "onResult: " + result);

                    if (result.isSuccess()) {
                        handleFloorPlanChange(result.getResult());
                    } else {
                        // do something with error
                        Toast.makeText(MainActivity.this,
                                "loading floor plan failed: " + result.getError(), Toast.LENGTH_LONG)
                                .show();
                    }
                }
            }, Looper.getMainLooper()); // deliver callbacks in main thread
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

When I tried to repair those error then no image loads nothing just happens. After this I tried their example from GitHub repo https://github.com/IndoorAtlas/android-sdk-examples There I tried to run ImageView Activity it throws error that mIAFloor is null object reference. Any help will be appreciated. This is my university task what I have to do to fetch that image from plan and navigate on that their docs and all that shit is not working.

0 Answers