this is the code in java for wrap a sdk jar:
this is the xml:
and this is the b4a code for call it:
this is the error log:
where is wrong please??:sign0085:
B4X:
package ice;
import cn.domob.android.ads.DomobAdListener;
import cn.domob.android.ads.DomobAdView;
import android.util.Log;
import anywheresoftware.b4a.*;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
@ShortName("AdView_domob")
@Version(1.01F)
@Author("IceFairy")
@DependsOn(values="domobsdk3.0")
@Events(values={"onReceivedFreshAd","onLandingPageOpening","onLandingPageClose","onFailedToReceiveFreshAd"})
@Permissions(values = {"android.permission.INTERNET","android.permission.READ_PHONE_STATE","android.permission.ACCESS_NETWORK_STATE","android.permission.ACCESS_COARSE_LOCATION","android.permission.WRITE_EXTERNAL_STORAGE"})
public class domobad extends ViewWrapper<DomobAdView> {
public static String ScreenSize_300X250=DomobAdView.INLINE_SIZE_300X250;
public static String ScreenSize_320X50=DomobAdView.INLINE_SIZE_320X50;
public static String ScreenSize_600X500=DomobAdView.INLINE_SIZE_600X500;
public static String ScreenSize_600X94=DomobAdView.INLINE_SIZE_600X94;
public static String ScreenSize_728X90=DomobAdView.INLINE_SIZE_728X90;
/**
*
* @param EventName
* @param publisherID Android public debud Publisher ID:56OJyM1ouMGoaSnvCK
* @param size ScreenSize_600X94 or other size string with "320X240"
* @param autoRefresh Boolean value
*/
public void Initialize(final BA ba,String EventName,String publisherID,String size) {
Log.i("B4A","initialize");
setObject(new DomobAdView(ba.activity, publisherID, size));
super.Initialize(ba, EventName);
final String eN = EventName.toLowerCase(BA.cul);
((DomobAdView)getObject()).setOnAdListener(new DomobAdListener() {
@Override
public void onReceivedFreshAd(DomobAdView adview) {
// TODO Auto-generated method stub
ba.raiseEvent(((DomobAdView)getObject()), eN+"onReceivedFreshAd", new Object[0]);
Log.i("B4A","onReceivedFreshAd");
}
@Override
public void onLandingPageOpening() {
// TODO Auto-generated method stub
ba.raiseEvent(((DomobAdView)getObject()), eN+"onLandingPageOpening", new Object[0]);
Log.i("B4A","onLandingPageOpening");
}
@Override
public void onLandingPageClose() {
// TODO Auto-generated method stub
ba.raiseEvent(((DomobAdView)getObject()), eN+"onLandingPageClose", new Object[0]);
Log.i("B4A","onLandingPageClose");
}
@Override
public void onFailedToReceiveFreshAd(DomobAdView adview) {
// TODO Auto-generated method stub
ba.raiseEvent(((DomobAdView)getObject()), eN+"onFailedToReceiveFreshAd", new Object[0]);
Log.i("B4A","onFailedToReceiveFreshAd");
}
});
return;
}
/**
*
* @param key set the keywords for request ads
*/
public void SetKeyWords(String key) {
((DomobAdView)getObject()).setKeyword(key);
return;
}
/**
*
* @param sex "male" or "female"
*/
public void SetSex(String sex) {
((DomobAdView)getObject()).setUserGender(sex);
return;
}
public void requestRefreshAd() {
((DomobAdView)getObject()).requestRefreshAd();
return;
}
public void requestAdForAggregationPlatform() {
((DomobAdView)getObject()).requestAdForAggregationPlatform();
return;
}
}
B4X:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<doclet-version-NOT-library-version>1.02</doclet-version-NOT-library-version>
<class>
<name>ice.domobad</name>
<shortname>AdView_domob</shortname>
<objectwrapper>cn.domob.android.ads.DomobAdView</objectwrapper>
<owner>process</owner>
<event>onReceivedFreshAd</event>
<event>onLandingPageOpening</event>
<event>onLandingPageClose</event>
<event>onFailedToReceiveFreshAd</event>
<permission>android.permission.INTERNET</permission>
<permission>android.permission.READ_PHONE_STATE</permission>
<permission>android.permission.ACCESS_NETWORK_STATE</permission>
<permission>android.permission.ACCESS_COARSE_LOCATION</permission>
<permission>android.permission.WRITE_EXTERNAL_STORAGE</permission>
<method>
<name>Initialize</name>
<comment>
ba:
EventName:
publisherID: Android public debud Publisher ID:56OJyM1ouMGoaSnvCK
size: ScreenSize_600X94 or other size string with "320X240"
autoRefresh: Boolean value</comment>
<returntype>void</returntype>
<parameter>
<name>ba</name>
<type>anywheresoftware.b4a.BA</type>
</parameter>
<parameter>
<name>EventName</name>
<type>java.lang.String</type>
</parameter>
<parameter>
<name>publisherID</name>
<type>java.lang.String</type>
</parameter>
<parameter>
<name>size</name>
<type>java.lang.String</type>
</parameter>
</method>
<method>
<name>RequestFocus</name>
<comment></comment>
<returntype>boolean</returntype>
</method>
<method>
<name>BringToFront</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>buildNativeView</name>
<comment></comment>
<returntype>T</returntype>
<parameter>
<name>arg0</name>
<type>android.content.Context</type>
</parameter>
<parameter>
<name>arg1</name>
<type>java.lang.Class</type>
</parameter>
<parameter>
<name>arg2</name>
<type>java.util.HashMap</type>
</parameter>
<parameter>
<name>arg3</name>
<type>boolean</type>
</parameter>
</method>
<method>
<name>RemoveView</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>SetBackgroundImage</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>arg0</name>
<type>android.graphics.Bitmap</type>
</parameter>
</method>
<method>
<name>SetSex</name>
<comment>
sex: "male" or "female"</comment>
<returntype>void</returntype>
<parameter>
<name>sex</name>
<type>java.lang.String</type>
</parameter>
</method>
<method>
<name>SetLayout</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<parameter>
<name>arg1</name>
<type>int</type>
</parameter>
<parameter>
<name>arg2</name>
<type>int</type>
</parameter>
<parameter>
<name>arg3</name>
<type>int</type>
</parameter>
</method>
<method>
<name>Invalidate</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>SetKeyWords</name>
<comment>
key: set the keywords for request ads</comment>
<returntype>void</returntype>
<parameter>
<name>key</name>
<type>java.lang.String</type>
</parameter>
</method>
<method>
<name>Invalidate3</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<parameter>
<name>arg1</name>
<type>int</type>
</parameter>
<parameter>
<name>arg2</name>
<type>int</type>
</parameter>
<parameter>
<name>arg3</name>
<type>int</type>
</parameter>
</method>
<method>
<name>requestAdForAggregationPlatform</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>Invalidate2</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>arg0</name>
<type>android.graphics.Rect</type>
</parameter>
</method>
<method>
<name>requestRefreshAd</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>SendToBack</name>
<comment></comment>
<returntype>void</returntype>
</method>
<method>
<name>IsInitialized</name>
<comment></comment>
<returntype>boolean</returntype>
</method>
<property>
<name>Enabled</name>
<returntype>boolean</returntype>
<parameter>
<name>arg0</name>
<type>boolean</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Top</name>
<returntype>int</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Visible</name>
<returntype>boolean</returntype>
<parameter>
<name>arg0</name>
<type>boolean</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Tag</name>
<returntype>java.lang.Object</returntype>
<parameter>
<name>arg0</name>
<type>java.lang.Object</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Height</name>
<returntype>int</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Background</name>
<returntype>android.graphics.drawable.Drawable</returntype>
<parameter>
<name>arg0</name>
<type>android.graphics.drawable.Drawable</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Width</name>
<returntype>int</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Left</name>
<returntype>int</returntype>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<comment></comment>
</property>
<property>
<name>Color</name>
<parameter>
<name>arg0</name>
<type>int</type>
</parameter>
<comment></comment>
</property>
<field>
<name>ScreenSize_600X94</name>
<comment></comment>
<returntype>java.lang.String</returntype>
</field>
<field>
<name>ScreenSize_300X250</name>
<comment></comment>
<returntype>java.lang.String</returntype>
</field>
<field>
<name>ScreenSize_600X500</name>
<comment></comment>
<returntype>java.lang.String</returntype>
</field>
<field>
<name>ScreenSize_320X50</name>
<comment></comment>
<returntype>java.lang.String</returntype>
</field>
<field>
<name>ScreenSize_728X90</name>
<comment></comment>
<returntype>java.lang.String</returntype>
</field>
</class>
<version>1.01</version>
<author>IceFairy</author>
<dependsOn>domobsdk3.0</dependsOn>
</root>
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim adv As AdView_domob
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Log(Activity.Width&"X"&Activity.Height)
adv.Initialize("adv","56OJyM1ouMGoaSnvCK","540X884")
adv.SetKeyWords("game")
Activity.AddView(adv,1,1,Activity.Width,100)
End Sub
Sub adv_onFailedToReceiveFreshAd
Log("加载广告错误")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
B4X:
** Activity (main) Create, isFirst = true **
540X884
initialize
dInitialize (B4A line: 17)
adv.Initialize("adv","56OJyM1ouMGoaSnvCK","540X884")
java.lang.NullPointerException
at android.view.ViewConfiguration.get(ViewConfiguration.java:232)
at android.view.View.<init>(View.java:1878)
at android.view.View.<init>(View.java:1921)
at android.view.View.<init>(View.java:1899)
at android.view.ViewGroup.<init>(ViewGroup.java:286)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
at cn.domob.android.ads.DomobAdView.<init>(SourceFile)
at cn.domob.android.ads.DomobAdView.<init>(SourceFile)
at ice.domobad.Initialize(domobad.java:39)
at ice.domob.main._activity_create(main.java:220)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:145)
at ice.domob.main.afterFirstLayout(main.java:84)
at ice.domob.main.access$100(main.java:16)
at ice.domob.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3859)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
where is wrong please??:sign0085:
Last edited: