Java Question Library Error...

DevBaby

Active Member
Licensed User
Longtime User
I have the following Library...

B4X:
package com.tapjoy.access;

import android.app.Activity;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.tapjoy.TapjoyConnect;
import com.tapjoy.TapjoyNotifier;


@DependsOn(values={"tapjoy_sdk"})
@Permissions(values={"android.permission.INTERNET", "android.permission.ACCESS_WIFI_STATE", "android.permission.READ_PHONE_STATE", "android.permission.ACCESS_NETWORK_STATE", "android.permission.WRITE_EXTERNAL_STORAGE"})
@ShortName("TapJoy")
@Version(1.0f)

public class tapjoyaccess extends Activity {

   
   /**
    * Send the registration to TapJoy  
    */
   public void RegisterTapJoy() {

      TapjoyConnect.requestTapjoyConnect(BA.applicationContext.getApplicationContext(), "dcb1e0a8-3e10-474f-b0b4-5d83b10d972e", "iC4cYd6oDdXYREnKUugs");
   
   }

   /**
    * Show OfferWall  
    */
   public void ShowOfferWall() {

      TapjoyConnect.getTapjoyConnectInstance().showOffers();
   
   }

   public void   CallTapPoints(final BA ba) { 

      TapjoyNotifier notifier1 = new TapjoyNotifier() {
         
         @Override
         public void getUpdatePoints(String currencyName, int points) {
            
            ba.raiseEvent(this, "tapjoyget_result", new Object[] { points });
         }
         
         @Override
         public void getUpdatePointsFailed(String error) {
            
            ba.raiseEvent(this, "tapjoyget_error", new Object[] { error.toString() });
         }
         
      };
      
      TapjoyConnect.getTapjoyConnectInstance().getTapPoints(notifier1);
   
   }
   
}


Below is the error I get when executing CallTapPoints.

Connected to B4A-Bridge (Wifi)
Installing file.
PackageAdded: package:am.lite.pkg
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (inappbillingservice) Create **
Could not bind to service.
BillingSupported: false
** Service (inappbillingservice) Start **
main_tapjoyget_result (java line: 10931)
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.app.Dialog.<init>(Dialog.java:106)
at android.app.AlertDialog.<init>(AlertDialog.java:63)
at android.app.AlertDialog.<init>(AlertDialog.java:59)
at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:415)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:383)
at am.lite.pkg.main._tapjoyget_result(main.java:10931)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at com.tapjoy.access.tapjoyaccess$1.getUpdatePoints(tapjoyaccess.java:47)
at com.tapjoy.TJCOffers.handleGetPointsResponse(TJCOffers.java:295)
at com.tapjoy.TJCOffers.access$0(TJCOffers.java:246)
at com.tapjoy.TJCOffers$1.run(TJCOffers.java:123)
at java.lang.Thread.run(Thread.java:1019)
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
main_tapjoyget_error (java line: 10924)
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.app.Dialog.<init>(Dialog.java:106)
at android.app.AlertDialog.<init>(AlertDialog.java:63)
at android.app.AlertDialog.<init>(AlertDialog.java:59)
at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:415)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:383)
at am.lite.pkg.main._tapjoyget_error(main.java:10924)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at com.tapjoy.access.tapjoyaccess$1.getUpdatePointsFailed(tapjoyaccess.java:53)
at com.tapjoy.TJCOffers$1.run(TJCOffers.java:128)
at java.lang.Thread.run(Thread.java:1019)
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.app.Dialog.<init>(Dialog.java:106)
at android.app.AlertDialog.<init>(AlertDialog.java:63)
at android.app.AlertDialog.<init>(AlertDialog.java:59)
at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:176)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at com.tapjoy.access.tapjoyaccess$1.getUpdatePointsFailed(tapjoyaccess.java:53)
at com.tapjoy.TJCOffers$1.run(TJCOffers.java:128)
at java.lang.Thread.run(Thread.java:1019)
** Activity (main) Pause, UserClosed = true **
 

DevBaby

Active Member
Licensed User
Longtime User
Hi Erel,

I am trying to call the getTapPoints function that gets the virtual coins managed on Tapjoy’s server. In return, one of the two methods (getUpdatePoints or getUpdatePointsFailed) are fired in a callback, for which I then raise an event in B4A to add the virtual currency.


I do not need “extends activity”.
 

DevBaby

Active Member
Licensed User
Longtime User
The code is on my Main Activity module...


B4X:
Sub tapjoyget_result(pointTotal As Int)

   Msgbox(pointTotal,"msg")

   If pointTotal = 0 Then
      
      Msgbox("You have no earned cash to collect.","No Game Cash")

   Else

      Calc.SetEarnCash(Round(pointTotal))
         
      Msgbox("You have earned $" & NumberFormat(pointTotal,0,0) & ".","Game Cash Added")
      
   End If   

End Sub


and

B4X:
Sub tapjoyget_error(error As String)

   Msgbox(error,"Error")

End Sub
 
Top