How to deal with E/JavaBinder: FAILED BINDER TRANSACTION that crashes the app?
I am making an android game using a SurfaceView.
I am also using a dedicated thread for the infinite Game-Loop itself, which contains both an update() method, as well as a draw() method.
The update() method updates characters position(logic) and sprites, while the draw() method draws to the canvas.
The dedicated thread handles both update() and draw() since they need to be synchronized.
The onTouchEvents (user clicks) are handled by the main thread.
Although I cannot tell for sure, I suspect that I am getting this error: E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! , because
both the draw() method and the update() method call other methods that call other methods and so on.. resulting in an almost a recursive behavior.
For example my update() method, calls characterOne.update().. which then calls characterOneSpells.update() which then calls spellOne.update() and so on... same thing for the draw(). I suspect that this overflows the bind buffer or something like that.. I am not sure.. and all of this is happening in an infinite loop infinite amount of times.
Note that I took this approach ( methods call methods that call other methods) because logically it made sense to me that a character should be responsible to draw itself, and a spell should be responsible to draw itself, rather than the character be responsible to draw and update the spells and so on. It made sense to me that every object should be responsible to draw itself and update itself, and that is my reasoning, I might be wrong, please let me know what you think.
Now, I am new to game making, and in fact this is my first game, so please take it easy on me, I am trying to learn!
Sample of my code and the error log can be found below.
Any insight to why I am getting this E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! and how to fix it would be very much appreciated! Also feel free to suggest a better design or approach, since I am trying to learn.
Thank you!
I marked the important parts of the code with ** Important ** comment to make things easier.`
ERROR LOG:
11-17 17:07:30.132 934-1460/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
11-17 17:07:30.388 1451-1451/? E/RecyclerView: No adapter attached; skipping layout
11-17 17:07:32.328 934-992/? E/InputDispatcher: channel '329e61e3 com.amazon.firelauncher/com.amazon.firelauncher.Launcher (server)' ~ Channel is unrecoverably broken and will be disposed!
11-17 17:07:32.407 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.442 934-1011/? E/WifiService: Multicaster binderDied
11-17 17:07:32.462 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.464 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.464 146-146/? E/lowmemorykiller: Error opening /proc/1217/oom_score_adj; errno=2
11-17 17:07:36.426 6868-6868/? E/cr_AWVDeploymentClient: Chromium Version = v59 key doesn't exist. So, default version config will be used.
11-17 17:07:36.428 6868-6868/? E/cr_AWVDeploymentClient: Default device config doesn't exist
11-17 17:07:39.313 934-992/? E/InputDispatcher: channel '11e88fc0 info.evyatar.mystrategygame/info.evyatar.mystrategygame.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-17 17:07:40.905 7010-7051/? E/SQLiteLog: (283) recovered 44 frames from WAL file /data/user/0/com.amazon.firelauncher/databases/producer.db-wal
11-17 17:07:41.091 7010-7059/? E/SQLiteLog: (283) recovered 90 frames from WAL file /data/user/0/com.amazon.firelauncher/databases/CardDeviceAgentDB-wal
11-17 17:07:43.558 7010-7010/? E/RecyclerView: No adapter attached; skipping layout
11-17 17:07:43.622 7089-7089/? E/TimeoutManagerClient: bindService() Failed to bind to ECService
11-17 17:07:43.631 7165-7165/? E/Dagger2: ApplicationModule context already set
11-17 17:07:44.924 7089-7311/? E/...iceDataCommunication: Got a RemoteMAPException
com.amazon.identity.auth.device.framework.RemoteMAPException: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key ke_device was not found in the device data store. This device does not support ke_device. This error is expected if the device not support ke_device.
at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:118)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52)
at com.amazon.identity.auth.device.devicedata.DeviceDataStoreSystemPropertyDecorator.getValue(DeviceDataStoreSystemPropertyDecorator.java:52)
at com.amazon.identity.auth.device.api.DeviceDataStore.getValue(DeviceDataStore.java:96)
at com.amazon.avod.identity.DeviceProperties.isKidsEditionDevice(DeviceProperties.java:374)
at com.amazon.avod.identity.DeviceProperties.initialize(DeviceProperties.java:201)
at com.amazon.avod.core.ApplicationComponents$InitializeDeviceProperties.initialize(ApplicationComponents.java:543)
at com.amazon.avod.core.ApplicationComponents$InitializeRunnable.run(ApplicationComponents.java:787)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key ke_device was not found in the device data store. This device does not support ke_device. This error is expected if the device not support ke_device.
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:93)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:61)
at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:112)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52)
at com.amazon.identity.auth.device.devicedata.DeviceDataStoreSystemPropertyDecorator.getValue(DeviceDataStoreSystemPropertyDecorator.java:52)
at com.amazon.identity.auth.device.api.DeviceDataStore.getValue(DeviceDataStore.java:96)
at com.amazon.avod.identity.DeviceProperties.isKidsEditionDevice(DeviceProperties.java:374)
at com.amazon.avod.identity.DeviceProperties.initialize(DeviceProperties.java:201)
at com.amazon.avod.core.ApplicationComponents$InitializeDeviceProperties.initialize(ApplicationComponents.java:543)
at com.amazon.avod.core.ApplicationComponents$InitializeRunnable.run(ApplicationComponents.java:787)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
11-17 17:07:45.701 7010-7085/? E/...iceDataCommunication: Got a RemoteMAPException
com.amazon.identity.auth.device.framework.RemoteMAPException: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key re_device was not found in the device data store. This device does not support re_device. This error is expected if the device not support re_device.
at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:118)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52
at java.lang.Thread.run(Thread.java:818)
Caused by: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key re_device was not found in the device data store. This device does not support re_device. This error is expected if the device not support re_device.
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:93)
at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:61)
at com.amazon.firelauncher.services.MapCache.updateDeviceData(MapCache.java:579)
at com.amazon.firelauncher.services.MapCache.access$700(MapCache.java:47)
at com.amazon.firelauncher.services.MapCache$3.run(MapCache.java:491)
at com.amazon.firelauncher.services.BackgroundExecutor$InternalRunnable.run(BackgroundExecutor.java:180)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
11-17 17:07:45.930 7343-7343/? E/SQLiteLog: (283) recovered 120 frames from WAL file /data/securedStorageLocation/com.amazon.providers.contentsupport/contentsupport.db-wal
11-17 17:07:45.979 7343-7343/? E/SQLiteLog: (284) automatic index on languages(packageId)
11-17 17:07:46.007 7343-7343/? E/SQLiteLog: (284) automatic index on languages(packageId)
11-17 17:07:47.386 7010-7417/? E/F_C.ArcusRemoteConfigur: No valid offline remote setting found for the current device, not setting default
java.lang.Exception: Error getting the baseline setting for Arcus config cms
at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:106)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.Exception: Exception reading from cms/baseline.json
at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:43)
at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:14)
at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:88)
at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:22)
at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration$1.map(ArcusRemoteConfiguration.java:67)
at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration$1.map(ArcusRemoteConfiguration.java:60)
at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration.initialize(ArcusRemoteConfiguration.java:117)
at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111)
at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.io.FileNotFoundException: cms/baseline.json
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:313)
at android.content.res.AssetManager.open(AssetManager.java:287)
at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:29)
at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:14)
at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:88)
at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111)
at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
11-17 17:07:47.400 7010-7417/? E/F_C.FireDeviceAttribute: BuildNumber is not a valid String attribute (wrong type: Integer)
11-17 17:07:47.416 7010-7417/? E/F_C.ArcusParameters: Exception getting attribute %s, no attribute added
java.lang.NullPointerException: attrValue cannot be null
at com.amazonaws.mobileconnectors.remoteconfiguration.internal.gear.Checks.checkNotNull(Checks.java:20)
at com.amazonaws.mobileconnectors.remoteconfiguration.internal.AttributesImpl.addAttributePrivate(AttributesImpl.java:193)
at com.amazonaws.mobileconnectors.remoteconfiguration.internal.AttributesImpl.addAttribute(AttributesImpl.java:103)
at com.amazon.firelauncher.reccardproducer.arcus.ArcusParameters.decorateManager(ArcusParameters.java:87)
at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration.initialize(ArcusRemoteConfiguration.java:119)
at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111)
at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Sample Code
public class GameLoop extends SurfaceView implements SurfaceHolder.Callback {
private Context myContext;
private SurfaceHolder mySurfaceHolder;
private Bitmap backgroundImg;
private int screenW = 1;
private int screenH = 1;
private boolean running = false;
private boolean onTitleScreen = true;
private GameLoopThread thread;
private int backgroundOrigW;
private int backgroundOrigH;
private float scaleW;
private float scaleH;
private float drawScaleW;
private float drawScaleH;
private int fingerX, fingerY;
private boolean isDragging = false;
SingltonAssetsObject mSingltonAssetsObject;
private boolean gameOver;
Point userClickPoint;
//Characters
CharacterTypeOne characterFighterOne,characterFighterTwo,characterFighterThree;
CharacterTypeTwo CharacterMage;
public GameLoop(Context context, AttributeSet attrs) {
super(context, attrs);
SurfaceHolder holder = getHolder();
holder.addCallback(this);
//init clickRectangle
userClickPoint = new Point();
//creates the gameLoop thread DRAW THREAD
thread = new GameLoopThread(holder,context);
setFocusable(true);
}
public void initCharacters(){
mSingltonAssetsObject = SingltonAssetsObject.getInstance(myContext,scaleW,scaleH);
characterFighterOne = new characterFighterOne(myContext,1000,1,150,350,100,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
characterFighterTwo = new characterFighterOne(myContext,1001,67,350,350,100,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
characterFighterThree = new characterFighterOne(myContext,1002,99,550,350,1000,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
characterMage = new characterMage(myContext,50,28,650,250,100,15,0.1,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
return thread.doTouchEvent(event);
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
thread.setSurfaceSize(width, height);
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
if (thread.getState() == Thread.State.NEW) {
thread.start();
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
thread.setRunning(false);
}
class GameLoopThread extends Thread{
public GameLoopThread(SurfaceHolder surfaceHolder, Context context){
//initialzied in inner class and not outter because this variable will act as a lock and will be shard with all threads
mySurfaceHolder = surfaceHolder;
myContext = context;
//the background image of the title screen
backgroundImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.title);
backgroundOrigW = backgroundImg.getWidth();
backgroundOrigH = backgroundImg.getHeight();
}
//This method is the main game loop
public void run() {
while (running) {
try { //lock canvas for drawing
c = mySurfaceHolder.lockCanvas(null);
synchronized (mySurfaceHolder) {
if (!gameOver)
{
//** important ***
updateAnimationsAndPosition();
}
// **important **
draw(c);
}
} finally {
if (c != null) { //unlock canvas
mySurfaceHolder.unlockCanvasAndPost(c);
}
}
} //while loop ends
} //run Method ends (gameLOOP)
//This method will draw everything to the screen
public void draw(Canvas canvas){
canvas.drawBitmap(backgroundImg, 0, 0, null);
if (!onTitleScreen) {
/* **Important**
Note: characterFighterOne.draw(canvas) calls spells.draw(canvas)
which calls spellOne.draw(canvas).. which call spellIndicartor.draw(canvas)
and so on... might be cauing the isssue?*/
characterFighterOne.draw(canvas);
characterFighterTwo.draw(canvas);
characterFighterThree.draw(canvas);
characterMage.draw(canvas);
}
}
//This method updates the animations, for example changes image every tick
public void updateAnimationsAndPosition(){
if(!onTitleScreen){
/***Important**
Note: characterFighterOne.updateAnimationsAndPosition() calls spells.update()
which calls spellOne.update().. which call spellIndicartor.update()
and so on... might be causing the issue?*/
characterFighterOne.updateAnimationsAndPosition();
characterFighterTwo.updateAnimationsAndPosition();
characterFighterThree.updateAnimationsAndPosition();
characterMage.updateAnimationsAndPosition();
}
}
public void setSurfaceSize(int width, int height) {
synchronized (mySurfaceHolder) {
screenW = width;
screenH = height;
backgroundImg = Bitmap.createScaledBitmap(backgroundImg, width, height, true);
drawScaleW = (float) screenW / 960; //screen/background width image
drawScaleH = (float) screenH / 640;
}
}
//This method is in charge of user input ( clicks on screen, and how to respond to them)
public boolean doTouchEvent(MotionEvent event){
if(!onTitleScreen){
characterFighterOne.doTouchEvent(event);
characterFighterTwo.doTouchEvent(event);
characterFighterThree.doTouchEvent(event);
characterMage.doTouchEvent(event);
userClickPoint.set((int)event.getX(),(int)event.getY());
}
synchronized (mySurfaceHolder) {
int eventaction = event.getAction();
int X = (int)event.getX();
int Y = (int)event.getY();
switch (eventaction ) {
case MotionEvent.ACTION_DOWN:
if(!gameOver){
fingerX = X;
fingerY = Y;
if (!onTitleScreen) {
}
}
break;
case MotionEvent.ACTION_MOVE:// used for dragging purposes
break;
case MotionEvent.ACTION_UP:
//Here I load all the images to memory ( while on the titleScreen normal size & scaled, find a better place, maybe OnCreate, leave for now)
if (onTitleScreen) {
backgroundImg = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.background);
backgroundImg = Bitmap.createScaledBitmap(backgroundImg, screenW, screenH, true);
onTitleScreen = false;
scaleW = (float) screenW/ (float) backgroundOrigW;
scaleH = (float) screenH/ (float) backgroundOrigH;
initCharacters();
}
if (gameOver) {
gameOver = false;
}
break;
}
}
return true;
}
//This method enables and disables the Thread
public void setRunning(boolean b) {
running = b;
}
}
}
when Im trying to add the Google play service to my Libgdx game that errors shows to me, I have no Idea from where to start.
any help?
06-08 00:04:29.626: I/System.out(3668): debugger has settled (1381)
06-08 00:04:29.774: D/dalvikvm(3668): Trying to load lib /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348
06-08 00:04:29.782: D/dalvikvm(3668): Added shared lib /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348
06-08 00:04:29.782: D/dalvikvm(3668): No JNI_OnLoad found in /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348, skipping init
06-08 00:04:30.962: D/dalvikvm(3668): threadid=1: still suspended after undo (sc=1 dc=1)
06-08 00:04:31.532: D/GameHelper(3668): GameHelper: Debug log enabled.
06-08 00:04:32.227: D/GameHelper(3668): GameHelper: Setup: requested clients: 1
06-08 00:04:32.306: W/PopupManager(3668): You have not specified a View to use as content view for popups. Falling back to the Activity content view. Note that this may not work as expected in multi-screen environments
06-08 00:04:36.837: D/AndroidRuntime(3668): Shutting down VM
06-08 00:04:36.837: W/dalvikvm(3668): threadid=1: thread exiting with uncaught exception (group=0x41646700)
06-08 00:04:36.868: E/AndroidRuntime(3668): FATAL EXCEPTION: main
06-08 00:04:36.868: E/AndroidRuntime(3668): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alnassre.ffeather.android/com.alnassre.ffeather.android.AndroidLauncher}: java.lang.NullPointerException
when I remove this.googleServices.signIn(); the game start normally.
public class FFeather extends Game {
public IGoogleServices googleServices;
public FFeather(IGoogleServices googleServices)
{
super();
this.googleServices = googleServices;.
this.googleServices.signIn();
}
....
the main android launcher:
public class AndroidLauncher extends AndroidApplication implements GameHelperListener,IGoogleServices {
private GameHelper _gameHelper;
private final static int REQUEST_CODE_UNUSED = 9202;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the GameHelper.
_gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
_gameHelper.enableDebugLog(true);
GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {
#Override
public void onSignInSucceeded() {
Gdx.app.log("AndroidLauncher", "start: onSignInSucceeded()");
}
#Override
public void onSignInFailed() {
Gdx.app.log("AndroidLauncher", "start: onSignInFailed()");
}
};
_gameHelper.setup(gameHelperListener);
// main code
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new FFeather(this), config);
}
#Override
public void signIn() {
Gdx.app.log("AndroidLauncher", "start: signIn()");
}
....
The interface IGoogleServices which I think the error related to.
public interface IGoogleServices {
public void signIn();
public void signOut();
public void rateGame();
public void submitScore(long score);
public void showScores();
public boolean isSignedIn();
}
I have three class in my app.
First extends Activity
public class TestProjActivity extends Activity {
/** Called when the activity is first created. */
String my ="";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new Runnable() {
public void run() {
Translation th = new Translation(this);
my = th.doSomeJob();
}
}).start();
Log.d("ONCREATE", my);
}
}
Second is DBHelper
public class DBHelper {
private final Context myContext;
public DBHelper(Context context) {
this.myContext = context;
}
}
and third one extends DBhelper
public class Translation extends DBHelper {
public Translation(Runnable runnable) {
super((Context) runnable);
}
public String doSomeJob(){
return "Yes I DID!";
}
}
future I will change this classes to do real job but now,
when I run this I get this error:
05-11 13:15:53.003: E/AndroidRuntime(512): Uncaught handler: thread Thread-8 exiting due to uncaught exception
05-11 13:15:53.028: E/AndroidRuntime(512): java.lang.ClassCastException: iKA.PROJ.TestProjActivity$1
05-11 13:15:53.028: E/AndroidRuntime(512): at another.pack.Translation.(Translation.java:10)
05-11 13:15:53.028: E/AndroidRuntime(512): at iKA.PROJ.TestProjActivity$1.run(TestProjActivity.java:20)
05-11 13:15:53.028: E/AndroidRuntime(512): at java.lang.Thread.run(Thread.java:1096)
05-11 13:15:53.053: I/dalvikvm(512): threadid=7: reacting to signal 3
05-11 13:15:53.053: E/dalvikvm(512): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-11 13:20:53.135: I/Process(512): Sending signal. PID: 512 SIG: 9
What do I wrong ?
You're trying to cast your Runnable into a Context. This is not possible
I think that you want to do is
Translation th = new Translation(TestProjActivity.this);
and
public Translation(Context context) {
super(context);
}
Translation constructor take Activity(Context). But Translation constructor signature take Runnable. I think this is your problem (wrong class cast from Context/Activity to Runnable).
I am developing an app for android that has to access another class, but i don't know why it doesn't work.
When run the App in android 2.3.3 it force closes, and I don't understand why. I think that the method is correct.
Log in the force close the phone android:
> app_vercode:1
device_model:u8800
build_version:111180
condition:1
processName:beta.tester
pid:13277
uid:10088
tag:null
shortMsg:java.lang.NullPointerException
longMsg:java.lang.NullPointerException: Unable to start activity ComponentInfo{beta.tester/beta.tester.BetaTesterActivity}: java.lang.NullPointerException
stackTrace:java.lang.RuntimeException: Unable to start activity ComponentInfo{beta.tester/beta.tester.BetaTesterActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at beta.tester.BetaTesterActivity.onCreate(BetaTesterActivity.java:23)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
... 11 more
Detail logs:
EDIT: This code already is correctly.
The code:
class BetaTesterActivity:
package beta.tester;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class BetaTesterActivity extends Activity {
public TextView text1;
private teste cmd;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1 = (TextView) findViewById(R.id.text1);
//Start the function
cmd = new teste();
cmd.start(this);
}
}
class teste:
package beta.tester;
public class teste {
//Function that I will start
public void start(BetaTesterActivity zav){
zav.text1.setText("Hello");
}
//
}
In class teste, you are creating a new BetaTesterActivity, which is useless. You need to use the instance created by the framework. Change your class teste to this:
public class teste {
//Function that I will start
public void start(BetaTesterActivity zav){
zav.text1.setText("Hello");
}
}
Then in the onCreate method of your activity class, you need to initialize cmd and then call start like this:
cmd.start(this);
I am having trouble with developing my Android application, I am currently using Eclipse and a Phidget RFID. My aim is to display the ID of the RFID in a piece of text on the Android device.
I have managed to display the ID through a println in the following pieces of code.
package myFood.myFood;
import com.phidgets.*;
import com.phidgets.event.*;
public class RFID {
static String x ="NULL";
public static final Object main(String args[]) throws Exception {
RFIDPhidget rfid;
rfid = new RFIDPhidget();
rfid.openAny();
//Begin the TagGained event, allowing for users to read the RFID values
rfid.addTagGainListener(new TagGainListener()
{
public void tagGained(TagGainEvent oe)
{
Object y = (oe.getValue());
x= y.toString();
}
});
long StartTime,RunTime;
StartTime=System.currentTimeMillis();
do{
RunTime=System.currentTimeMillis();
if (x.equals("NULL")) {
//Continue waiting for input
}
else
StartTime = 10000; //Overload the result so the loop ends
}
while (RunTime-StartTime<5000);
rfid.close();
return x;
}
}
and then.
package myFood.myFood;
public class RFIDresult {
public static final Object main(String args[]) throws Exception {
System.out.println("Results");
Object x = RFID.main(args);
System.out.println(x);
return x;
}
}
However I want the ID to be displayed in a piece of text so I tried to develop the second piece of code into Android.
package myFood.myFood;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AddFood extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addfood);
Button mybutton = (Button) findViewById(R.id.Button1);
mybutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String[] args = null;
Object x = null;
try {
x = RFID.main(args);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextView mytext=(TextView)findViewById(R.id.widget96);
mytext.setText((CharSequence) x);
}
});
}
}
And this just generates a force close. I am a bit of a novice at this and will appreciate all the advice I get.
LogCat Report;
ERROR/AndroidRuntime(519): FATAL EXCEPTION: main
ERROR/AndroidRuntime(519): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(519): at myFood.myFood.RFID.main(RFID.java:9)
ERROR/AndroidRuntime(519): at myFood.myFood.AddFood$1.onClick(AddFood.java:26)<br/>
ERROR/AndroidRuntime(519): at android.view.View.performClick(View.java:2408)
ERROR/AndroidRuntime(519): at android.view.View$PerformClick.run(View.java:8816)
ERROR/AndroidRuntime(519): at android.os.Handler.handleCallback(Handler.java:587)
ERROR/AndroidRuntime(519): at android.os.Handler.dispatchMessage(Handler.java:92)
ERROR/AndroidRuntime(519): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(519): at android.app.ActivityThread.main(ActivityThread.java:4627)
ERROR/AndroidRuntime(519): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(519): at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(519): at om.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
ERROR/AndroidRuntime(519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
ERROR/AndroidRuntime(519): at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(519): Caused by: java.lang.ExceptionInInitializerError: Library phidget21 not found
ERROR/AndroidRuntime(519): Could not locate the Phidget C library (libphidget21.so).
ERROR/AndroidRuntime(519): Make sure it is installed, and add it's path to LD_LIBRARY_PATH.
ERROR/AndroidRuntime(519): at com.phidgets.Phidget.<clinit>(Phidget.java:34)
ERROR/AndroidRuntime(519): ... 13 more
You need to get myText from 'view' parameter. Try this:
TextView mytext=(TextView)**view**.findViewById(R.id.widget96);