How can I render some things using SpriteBatch?  I tried to do in this way:  Main class  static SpriteBatch batch;  public void render() {     Renderer.drawThing(); }   Renderer class  static drawThing() {     main.batch.begin();     //drawing some things     main.batch.end(); }   And it throws a NullPointerException. What am I doing wrong?
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
41889
I am just starting out in game development and I am trying to make a simple android game using GDXLib. I want to make my sprite "ball" jump straight up in the air and then return to where it originally was. How would I do this? I have looked at multiple other answers from similar questions but none seem to work with my code. This is my code so far:  @Override public void create () {     batch = new SpriteBatch();     background = new Texture("gamebackground.png");      ball = new Texture("ball2.png");     ball.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);      spike1 = new Texture("spike1.png");     spike1.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);     spike2 = new Texture("spike2.png");  }  @Override public void render () {      batch.begin();     float scaleFactor = 2.0f;     batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());     batch.draw(ball, 80, 145, ball.getWidth() * scaleFactor, ball.getHeight() * scaleFactor);     batch.end();  Gdx.input.setInputProcessor(new InputAdapter () {         @Override            public boolean keyDown (int keycode) {             if(keycode==Keys.UP)             {                ball.setHeight(ball.getHeight()+50);             }             return true;      }   @Override public void dispose () {  }   }
17504
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, including more unit test resources, navigate to the  tag.  I'm testing asynchronous code - like Batch Apex, Queueable Apex, @future methods, or Scheduled Apex - and I'm getting unexpected results. It seems like portions of my code aren't running, or I'm getting confusing errors about batch invocations. How do I effectively test this kind of code?
91785
Basically, I applied my textures by taking each individual object, unwrapping it in the uv editor, then opening up an image in the uv editor and it would apply the texture in the 3D editor. However, when I render my project none of the textures appear and everything looks odd. I don't know how to set up the images properly with the bee.  For example, here's the uv layout image for the bee's Cube.001:     How do I get that applied properly to the Cube.001 in my project?  Here is   Everything appears purple if the images aren't there and I don't know how to fix that either.
16110
Essentially, my problem is that i am trying to render a scene, however, blender crashes on me early during the render. I only have about 14 total objects in the scene. (It's not that complex) I tried to render a different blender file which was bigger than the one that i am having problems with, and the scene renders just fine. There is no difference in the render presets for both of these files. However, i still cannot render the other scene. It gets to preparing scene data, but then it crashes.  Thank you.
117953
I have a question. Is it possible to draw a sprite from a side view and then rig that with bones? Maybe I would first have to import the image into blender and then dop that outline with a mesh. Then, if even possible, I could maybe attach the sprite to the mesh and add the bones. I dont really have much experience with blender but I did create a humanoid sculpture and successfully rig it a long time ago. I don't remember being able to paste an image to the mesh in blender, but I do remember something having to do with seams and then maybe I could export those parts and attach it to them in another program (or worse have to draw over them which means having to draw the image all over again.) I'm not much of an art guy, more of a coding guy. I use Unity and would like to only have to draw one image and then do all the animations of that one image in blender so that I can focus more on coding. If it is possible please let me know. Thank you in advance for any response.
94044
So I came across  about a new  to render to SVG. That sounds great and all but how can it actually be done? Which buttons give me an SVG file at the end and where are they?  It seems pretty common for many blender/gimp plugins to simply not say how to use them. Even if the installation goes fine, there's no mechanism to find out what new buttons or menus exist.  Similar questions:
55795
I've seen somewhere rendering technique that allows order-less rendering of partially transparent sprites/objects.  Though I can't remember what the technique is called, so I'm having trouble Googling it.
43400
So far I've been using public void run() {} methods to execute my code in Java. When/why might one want to use main() or init() instead of run()?
35592
I've bougth cup models from internet.   In the ZIP I get the blend file and pressing F12 I can render the project (Do you call it project?)  But I don't see anymore the "Layout" tab, that is what I use the most.   Why and how can I go back to my usual interface?    Like in the Opening Layout:    UPDATE 1  I could open the file with the default layout, however I'm not seeing the objects in there:    UPDATE 2  How to open Collection 1? It's grayed out.
59367
I got a situation where i need to invoke future method from batch class. And i know that it is not possible to do. But there might be some workarounds to achieve it, right? And i dont want to invoke future method using shedule apex as my requirement will hit governor limits of "Total number of schedule jobs exceed". So i tried in below ways, but still fighting with same issue.  My design is  Scenario 1 :   Schedule Apex ===> 2. BatchClass (Runs every hour) (Generates a map with "N" records for every batch context, and passes it to Future method in an apex class)  ===> 3. Future method ( then it will login to a salesforce account and generates an attachment and sends an email to a corresponding email address) .   Scenario 2 :  Since, It is not possible to invoke future method from batch, i tried implementing an apex class with a normal static method  invoking future method and in a batch class, for every context i.e., execute() method, it will invoke a normal method which in turn invokes future method, but still got the same error      FATAL ERROR: Future method cant be called from future or Batch   ie.,   global class BatchClass implements Database.batachable&lt;Sobject&gt; {    global Iterable&lt;ScheduledReport__c&gt; start(Database.BatchableContext BC)  {         query=[];        return query;  }  global void execute(Database.BatchableContext BC, List&lt;ScheduledReport__c&gt; scope) {      FutureClass.normalMethod(mapRecords);   }    global void finish(Database.BatchableContext BC){   }  }   Future Class:   global class FutureClass {  global static void normalMethod(Map&lt;&gt; mapR) {      futureMethod(mapR);  }  @future(callout=true)  global static void futureMethod(Map&lt;&gt; m) {      //some code;   }  }   Scenario 3 :  Instead of invoking future class method from batch i tried updating list of records and done checkbox value to true and i've implemented after update event trigger to get the all the records in which checkbox values are true and from trigger i tried invoking future method , still didnt work , i got an error      FATAL ERROR: Future method cant be called from future or Batch   Please help me out.   Thanks !
44160
I have a Batch class that sends an Email from its finish method and want to test that. a But....I cannot test it. The the above test fails as there was no email invocation at all. BUT: I see it in the Limits view of my Dev Console that indeed one email invocation happens. Why?!  The batch class:  public MyBatch implements Database.Batchable&lt;SObject&gt; {      ...      public void finish(Database.BatchableContext context) {         sendEmail();     } }   The test method:  @isTest private static void sendsEmailOnFinish() {      Test.startTest();        MyBatch b = new MyBatch();     Database.executeBatch(b);     Test.stopTest();       // Verify     System.assertEquals(1, Limits.getEmailInvocations()); }   I thought this might be connected to using Test.startTest() and stopTest() but even moving the assertEquals before the Test.stopTest() doesn't make my test run.
98455
I noticed in Unity3D that each gameObject(entity) have its own renderer component, as far I understand, such component handle rendering logic.  I wonder if it is a common practice in entity/component based engines, when single entity have renderer components and logic components such as position, behavior altogether in one box?  Such approach sound odd to me, in my understanding entity itself belongs to logic part and shouldn't contain any render specific things inside.  With such approach it is impossible to swap renderers, it would require to rewrite all that customized renderers.  The way I would do it is, that entity would contain only logic specific components, like AI,transform,scripts plus reference to mesh, or sprite. Then some entity with Camera component would store all references to object that is visible to the camera. And in order to render all that stuff I would have to pass Camera reference to Renderer class and render all sprites,meshes of visible entities.  Is such approach somehow wrong?
114984
Is it possible to control the shading via a node in the compositor? I would like to generate two output images, one which has material shading and one without any shading - just the colors from the texture.   So far I only found how to control this option with the UI (of course) and with Python, but with these methods I have to render the image twice, which is somehow an overhead.
36957
I was watching a tutorial how to design an island in Blender, which worked really great, but i didn't want to use the .png Trees the guy used there. So i watched another tutorial and created another kind of tree - without knowing that the object isn't just modeled in Cycles Render, it is also rendered in there.  My problem is either the (lets say "simple" textured) island (rendered in Blender render) or the tree is shown. Is there any way i can "convert" that cycles object (with its shaders) to Blender Render or the other way around? Or just render with two renders in one project? I haven't found something about that til now. If there is no universal solution for that, i could also put a link to my project in here.
81281
I'm trying to make a script where I have to render several images of the same scene at the same frame, and write to disk with appropriate names. The problem is that although this works fine with a non-responsive UI, it doesn't work well when the render progress appears in the Blender UI.  I mean,  bpy.ops.render.render()   uses "EXEC_DEFAULT" when called from a script. This leaves a blocked User Interface until the render finishes, meaning that you can't cancel the process, except by killing Blender. The problem is that the render may be too big in resolution, and the user could want to stop the process when realizing that the render could take hours, so the idea is to cancel this process without losing the currently opened project.  If I call,  bpy.ops.render.render("INVOKE_DEFAULT")   I get a nice preview bar in the Info Window with a clickable "X" button. I want the user to be able to press that button to cancel the operation if needed, but for a series of renders (not animation).  The problem here seems to be when trying to loop this command with the INVOKE_DEFAULT context to write several renders. I made a lot of testing, and this way of calling the render operator seems to continue with whatever is next in the script, so it loops very fast and ends before the rendering actually finishes.  I think that I need some way to stop the script and make it wait until render finishes to continue looping with the next ones. I tried the "render_complete" and "render_cancel" handlers, but I can't use them to start a new render or even make the rest of the script wait until the loop of renders is complete. I tried threading and events without success either. Maybe I'm doing something wrong.  import bpy  render = bpy.context.scene.render path = render.filepath = "/tmp/" shots = ["one", "two", "three"]  for x in shots:     render.filepath = path + x     bpy.ops.render.render("INVOKE_DEFAULT", write_still=True) # this doesn't work      # but if I use:     # bpy.ops.render.render(write_still=True)     # without the INVOKE thing, images are written as expected,     # but losing the possibility to see the progress and cancel rendering
25560
Lots of times in Java logs I'll get something like:  Caused by: java.sql.BatchUpdateException: failed batch     at org.hsqldb.jdbc.jdbcStatement.executeBatch(jdbcStatement.java:1102)     at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(jdbcPreparedStatement.java:514)     at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)     ... 113 more   Does anyone know how to get the full stacktrace showing (i.e. show the other 113 lines)?    The  for Throwable have a pretty detailed explanation of what's going on.