Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:27:52+00:00 2026-05-25T19:27:52+00:00

The following code shows a torus slowly revolving and coming into display: package com.objloader.example;

  • 0

The following code shows a torus slowly revolving and coming into display:

package com.objloader.example;

import ...
public class ObjLoaderProg implements ApplicationListener{
    String torus;
    Mesh model;
    private PerspectiveCamera camera;
    @Override
    public void create() {
        InputStream stream=null;
        try {
            stream = new FileInputStream(Gdx.files.internal("data/torus.obj").path());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        model = ObjLoader.loadObj(stream, true);
        Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
        Gdx.gl10.glTranslatef(0.0f,0.0f,-3.0f);
    }

    @Override
    public void dispose() {
    }

    @Override
    public void pause() {
    }

    protected int lastTouchX;
    protected int lastTouchY;
    protected float rotateZ=0.01f;
    protected float increment=0.01f;

    @Override
    public void render() {
        Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        camera.update();
        camera.apply(Gdx.gl10);
        Gdx.gl10.glTranslatef(0.0f,0.0f,-3.0f);
        Gdx.gl10.glRotatef(rotateZ, rotateZ, 5.0f, rotateZ);
        model.render(GL10.GL_TRIANGLES);

         if (Gdx.input.justTouched()) {
              lastTouchX = Gdx.input.getX();
              lastTouchY = Gdx.input.getY();
            } else if (Gdx.input.isTouched()) {
              camera.rotate(0.2f * (lastTouchX - Gdx.input.getX()), 0, 1.0f, 0);
              camera.rotate(0.2f * (lastTouchY - Gdx.input.getY()), 1.0f, 0, 0);

              lastTouchX = Gdx.input.getX();
              lastTouchY = Gdx.input.getY();
            }
         rotateZ+=increment;
         System.out.println(""+rotateZ);
    }

    @Override
    public void resize(int arg0, int arg1) {
        float aspectRatio = (float) arg0 / (float) arg1;
        camera = new PerspectiveCamera(67, 2f * aspectRatio, 2f);
        camera.near=0.1f;
        camera.translate(0, 0, 0);
    }

    @Override
    public void resume() {
    }
}

It renders a torus obj that’s saved in the data folder, and by clicking and dragging on the screen the user can rotate the camera.

This works fine on the desktop, but when I try to run it on android, I get a NullPointerException at:

model.render(GL10.GL_TRIANGLES);

I’ve tried placing torus.obj just inside assets, and within assets/data. I’m using libgdx 0.9.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:27:53+00:00Added an answer on May 25, 2026 at 7:27 pm

    I assume you are referring to model.render(GL10.GL_TRIANGLES);. I believe you have two problems. First, model is null because you are catching a FileNotFoundException and ignoring it. I suggest you don’t catch the FileNotFoundException right now, let it crash, and look at the stack trace. That will give you a better indication of why this failing. Note that e.printStackTrace() is not useful for debugging on android, try using the gdx log.

    The second problem is that I suspect the path/stream is actually going to the wrong place. Instead of creating a FileInputStream, use the FileHandle.read() function. It returns a java.io.InputStream that you can pass to ObjLoader.loadObj().

    in = Gdx.files.internal("data/torus.obj").read();
    model ObjLoader.loadObj(in);
    in.close();
    

    The difference between this and your code is that FileHandle.read() in libgdx’s android backend uses the android AssetManager to open files that are bundled with the program.

    Finally, copy the torus.obj file to <YourAndroidProject>/assets/data/torus.obj.

    An aside: if you specify the line number, please provide the full file otherwise the line will be off. Line 52 of the code you have provided is: lastTouchY = Gdx.input.getY();. Note the “import …” at the beginning of your code. Those imports affect the line number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that shows either a bug or a misunderstanding on
The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
The following code is in the /Courses/Detail action: [AcceptVerbs(GET)] public ActionResult Detail(int id) {
The following code shows what I expect in Firefox and Chrome: a small white
The following code shows a bug I'm trying to fix. I have two ways
The following code shows a button that allows you to select a file (should
the following code shows invalid qualifier when executed Dim strs As String Dim insStr
The following code shows me that cacheasbitmap is turning on and off like it
I'm sure this is a really simple question. The following code shows what I'm
The following code is implemented in Page_Load event to show SaveFileDialog to the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.