Problem beim GoogleAdMob für die App

A

~ aerox

Neues Mitglied
0
Moin liebe cm,
ich hoffe ich bekomme hier hilfe bin ganz verzweifelt >.<

Ich bin ein recht "Anfänger" in sachen Java Programmierung, habe damals eine etwas ähnliche Sprache gelernt, die Pawn Sprache (Scripting).

Der Einstieg gelangte mir gut, ich habs mal mit einer Soundboard App probiert, klappt alles ganz gut also das Konzept, nur ein bekannter meinte ich soll dort nun Werbung einblenden lassen (GoogleAdMob).

Ich bin diesem Tutorial nachgegangen:
blog.kerul.net: Installing Google AdMob into Android Apps

https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals?hl=de-DE

Soweit alles gut, nur bei einer Sache in der SoundboardActivity.JAR Datei gabs denn ersten Error -.-
Hier mal mein Code wie es in meiner .Jar datei steht:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]package 
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]tesdt.ads;[/SIZE] 

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.app.Activity;[/SIZE] 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.os.Bundle; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.media.MediaPlayer; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View.OnClickListener; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.Button; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.LinearLayout;[/SIZE] 

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]com.google.ads.*;[/SIZE] 

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=red] [U]Bannertest[/U][/COLOR] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AdListener {[/SIZE] 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AdView [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]


[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) {[/SIZE] 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]

[SIZE=2]String MEINEPUBLISHERID;[/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Create the adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AdView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], AdSize.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]BANNER[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], MEINEPUBLISHERID);[/SIZE]

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Lookup your LinearLayout assuming it’s been given[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// the attribute android:id="@+id/mainLayout"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]LinearLayout layout = (LinearLayout)findViewById(R.id.[/LEFT]
[/LEFT]
[/SIZE][LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE] 

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Add the adView to it[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]layout.addView([/LEFT]
[/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE] 

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Initiate a generic request to load it with an ad[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].loadAd([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AdRequest());[/SIZE]
[SIZE=2]}[/SIZE]

[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onDestroy() {[/SIZE] 
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].destroy();[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onDestroy();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]

[SIZE=2][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SoundboardActivity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity { [/SIZE]

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] MediaPlayer [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]
[SIZE=2]Button [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE]

[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) { [/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState); [/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]

[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (Button) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]bAudio[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (Button) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]bAudio2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]

[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener() { [/SIZE]

[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(View v) { [/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = MediaPlayer.[I]create[/I](getApplicationContext(), R.raw.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sound1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].start(); [/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2]}); [/SIZE]

[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]audio2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener() { [/SIZE]

[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(View v) { [/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = MediaPlayer.[I]create[/I](getApplicationContext(), R.raw.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sound2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].start(); [/SIZE]
[SIZE=2]} [/SIZE]
[SIZE=2]}); [/SIZE]




[SIZE=2]} [/SIZE][/LEFT]
[SIZE=2]} [/SIZE]

Dort wo der Error kommt, hab ich mal Rot unterstrichen.
Hier der Error:
Multiple markers at this line
- The type Bannertest must implement the inherited abstract method AdListener.onDismissScreen(Ad)
- The type Bannertest must implement the inherited abstract method AdListener.onPresentScreen(Ad)
- The public type Bannertest must be defined in its own file
- The type Bannertest must implement the inherited abstract method AdListener.onLeaveApplication(Ad)
- The type Bannertest must implement the inherited abstract method AdListener.onReceiveAd(Ad)
- The type Bannertest must implement the inherited abstract method AdListener.onFailedToReceiveAd(Ad, AdRequest
$ErrorCode)

Wie mach ich das das es weg geht? Bzw. was muss ich anstatt Bannertest einfügen ? Damit kein Error mehr kommt.. Ich bin da sau verzweifelt seid 3 Tagen -.-

Kann mir da bitte jemand helfen ??? Wäre echt super nett !!!

Danke im vorraus,
Mfg.
Kamil
[/LEFT]
 
Siehe hier:
class Bannertest extends Activity implements AdListener
Wenn du schon AdListener angibst, so musst du die Methoden auch implementieren. Das hat nichts mit Admob zu tun, das ist plain Java.
 
Danke für die schnelle Antwort!
Bitte genauere angaben da ich noch ein Anfänger bin versteh ich das grad net ^^

Aber auch wenn ich das wegmache
implements
AdListener
Kommt trotzdem der selbe Error, die Funktion hab ich nur iwo mal in Google gefunden und eingebunden hat aber nichts gebracht.
LG.
 
1. Deine Klassen müssen alle in eine eigene Datei.
2. Wenn du ein Interface (AdListener) angibst mit "implements" müssen die Methoden auch implementiert werden.

3. openbook.galileocomputing.de/javainsel8/
 
Ja und wie implementier ich diese ? Oder wo genau ? :p
danke im voraus.

LG
 
Ich rate dir dringend dazu meinen Link unter Punkt 3. zu öffnen und durchzuarbeiten.
Wenn du die absoluten Basics von Java nicht kennst bringt das sonst alles nichts.
 
Des hab ich ja schon alles fertig nur der Error kommt hier bei, weil ich zwei public class NAME
gemacht habe, dort steht dann folgendere Error
Code:
[SIZE=1][LEFT]Multiple markers at this line[/LEFT]
- The public type Bannertest must be defined in its own file

Ich will nur wissen was ich anbei der .JAR datei machen muss das der ERROR weg geht das mit dem implements brauch ich eigt. garnet dabei.

LG.
[/SIZE]
 
Du musst nichts in der JAR machen.
Du musst für jede Klasse eine eigene .java Datei haben. Es können nicht 2 unabhängige Klassen in einer Datei stehen. Aber das steht doch auch in dem Fehler den du kriegst.
 
Uppss verschrieben, meinte .java datei ^^

Naja ich hab jetzt eine neue Java datei erstellt und nun geht das, nur gibts wieder ein Error bei meiner Publisher ID
Undswar steht bei der Vorlage folgendes:
Code:
 adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

Also ersetzte ich das My_AD_UNIT_ID mit meiner.
In der Main.xml gefundene M.a.unit...
Code:
[SIZE=2][COLOR=#7f007f]
[SIZE=2][COLOR=#7f007f]ads:adUnitId[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"a14f4e76c0d8621"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE]

Das ganze sieht nun so aus:
Code:
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]adView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AdView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], AdSize.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]BANNER[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [U][COLOR=red]a14f4e76c0d8621[/COLOR][/U]);[/SIZE]
Error:
Code:
[LEFT][SIZE=1]- a14f4e76c0d8621 cannot be resolved to a [/SIZE][/LEFT]
[SIZE=1]variable[/SIZE]

Also hab ich oben mit String a14f4e76c0d8621;
sollte gehen, aber nun kommt wieder ein Error:
Code:
[LEFT][SIZE=1]Multiple markers at this line[/SIZE]
[SIZE=1]- Line breakpoint:Bannertest [line: 21] - onCreate(Bundle)[/SIZE]
[SIZE=1]- The local variable a14f4e76c0d8621 may not have been [/SIZE][/LEFT]
[SIZE=1]initialized[/SIZE]

Wie kann ich diesen umgehen >.<

Danke im vorraus.
 
Zuletzt bearbeitet:
a14f4e76c0d8621 IST dein String... setz den mal in ""
 
Danke, soweit alles klar. Keine Errors diesmal.. :scared:
Nur leider wenn ich denn Virtual Device starte erscheint nicht das AdMob was eigt. oben oder unter einblenden sollte ? Worran kann das liegn
 
Wahrscheinlich weil es in der falschen Activity ist...
 
Ich habe ja eine zweite .Java datei erstellt neber meiner SoundboardActivity in dem selben Ordner und dort den Codeschnipsel eingefügt?
Richtig so ? Oder musste ich den Codeschnipsel in meine bereits vorhandene .Java Datei einfügen un dort dann das Public class blabla
weglassen ?

Lg.

/e: Meine Frage ist, kann ich einfach eine .Java Datei im Ordner erstellen ohne es iwo im Manifest oder so zu definieren bzw. zu sagen das es die Datei gibt und die benutzt werden soll ??

Mfg.
 
Zuletzt bearbeitet:

Ähnliche Themen

netfreak
  • netfreak
Antworten
10
Aufrufe
438
netfreak
netfreak
Chrilos
Antworten
9
Aufrufe
569
koje71
koje71
R
  • Robby1950
2
Antworten
23
Aufrufe
956
Robby1950
R
Zurück
Oben Unten