0

我一直在网上关注如何构建android应用程序的教程,直到今天一切都很好,我一直在尝试admob,首先我按照教程,我的应用程序崩溃了java和xml添加admob的方式。然后我按照 admob.com 上的说明进行操作。有谁知道如何解决这个问题?我是 OOP(Java/Android)的新手。

这是错误日志:

03-01 20:02:06.910: E/AndroidRuntime(4670): <-- 所有行都以此开头。

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.ads.AdView
at com.example.myfirstapp.Data.onCreate(Data.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

数据.java:

package com.example.myfirstapp;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class Data extends Activity implements OnClickListener {

    private AdView ad;
    Button start, startFor;
    EditText sendET;
    TextView gotAnswer;
    RelativeLayout rl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get);
        initialize();
        ad = new AdView(this, AdSize.BANNER, "a151303d6f29c9c");
        rl = (RelativeLayout) findViewById(R.id.relLayout);
        rl.addView(ad);
        ad.loadAd(new AdRequest());

    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        if (ad != null) {
            ad.destroy();
        }
        super.onDestroy();
    }

    private void initialize() {
        // TODO Auto-generated method stub
        start = (Button) findViewById(R.id.bSA);
        startFor = (Button) findViewById(R.id.bSAFR);
        sendET = (EditText) findViewById(R.id.etSend);
        gotAnswer = (TextView) findViewById(R.id.tvGot);
        start.setOnClickListener(this);
        startFor.setOnClickListener(this);

    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch (arg0.getId()) {
        case R.id.bSA:
            String bread = sendET.getText().toString();
            Bundle basket = new Bundle();
            basket.putString("key", bread);
            Intent a = new Intent(Data.this, OpenedClass.class);
            a.putExtras(basket);
            startActivity(a);
            break;
        case R.id.bSAFR:
            Intent i = new Intent(Data.this, OpenedClass.class);
            startActivityForResult(i, 0);
            break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Bundle basket = data.getExtras();
            String s = basket.getString("answer");
            gotAnswer.setText(s);
        }
    }

}
4

1 回答 1

0

我的猜测是您的 Android 项目没有正确配置,因为 AdView 类似乎在编译时存在,但在运行时不存在,这表明该项目确实引用了 Admob 库但打包的应用程序(apk)没有。现在,由于您的问题不包括有关您正在使用的开发环境的信息,因此我无法为您提供解决问题的具体说明。

当然,如果您可以发布 Data.java 代码,至少是 onCreate() 方法以查看您在第 31 行所做的事情,这也会有所帮助。

于 2013-03-03T04:35:31.437 回答