1
\$\begingroup\$

I am making a LibGDX app, and I need to get the view to put to an Android app. Here is the code to get the view:

package jangkoo.game.shadowfiend.android;

import jangkoo.game.shadowfiend.ShadowFiendGame;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class LibGdx extends AndroidApplication {
    private static final String TAG = "LibGDx";
    public View view;
    Bundle savedInstanceState;
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        if(savedInstanceState == null)
        this.savedInstanceState = getIntent().getExtras();
        Log.e(TAG,savedInstanceState + "");
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        view = initializeForView(new ShadowFiendGame(), config);

    }
    public LibGdx(){
        onCreate(new Bundle());
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        }
}

And I want to get the libGDX.view from this,for a class that doesn't extend AndroidApplication.

protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    interstitialAd = new IntestialAds(this);
    inflater = LayoutInflater.from(this);
    config = new AndroidApplicationConfiguration();
    libGdx = new LibGdx();
    Log.e(TAG,libGdx.view + "");
}

However, the onCreate function has nullpointer exception. How can I handle this?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

I don't know if this is the Problem, but your LibGdx.onCreate() is calling LibGdx() which calls the onCreate() again.

\$\endgroup\$
1
\$\begingroup\$

If you mean by view the screen size / viewport , you could use the ScreenViewport function of libgdx.. ScreenViewport (LibGDX API)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .