2016-02-11 61 views
0

我的腳本後顯示圖像,每次我在Android工作室上運行它,但每次我嘗試運行腳本它發佈後,我不斷收到錯誤顯示勝利臉的有趣圖片。我不太清楚爲什麼每次運行腳本時都會出現錯誤,因爲當我放入笑臉圖像時,它會起作用。錯誤當試圖在Android工作室(Java)上添加圖像

這裏的腳本:

package com.udacity.gamedev.logging; 

import com.badlogic.gdx.ApplicationAdapter; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.graphics.Texture; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 

public class LoggingDemo extends ApplicationAdapter { 

    // TODO: Give your ApplicationListener a log TAG] 
    public static final String TAG = LoggingDemo.class.getName(); 


    SpriteBatch batch; 
    Texture img; 

    @Override 
    public void create() { 
     batch = new SpriteBatch(); 
     img = new Texture("Trump.jpg"); 

     // TODO: Use Gdx.app to find what ApplicationType we're running 
     // TODO: Use Gdx.app to log the result 
     Gdx.app.log(TAG, "We're running on" + 
       Gdx.app.getType() 

     ); 

    } 

    @Override 
    public void render() { 
     Gdx.gl.glClearColor(1, 0, 0, 1); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     batch.begin(); 
     batch.draw(img, 0, 0); 
     batch.end(); 
    } 

    // TODO: Run the Desktop app and find your log message 
    // TODO: Run the Android app and find your log message 
} 

這裏的錯誤: enter image description here

回答

0

你必須把文件Trump.jpg的Android項目的資產文件夾下。是你做的嗎?基於例外,它不在那裏。

並使用命令

new Texture(Gdx.files.internal("Trump.jpg")); 

初始化紋理對象。

如果它仍然不能清理您的項目。我不知道Android Studio,但是在Eclipse中,您可以選擇項目並單擊Project/Clean來清理並重建應用程序。