Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;无法解析linearLayout或它不是字段;使用谷歌针对Android的AdMob指令_Android_Eclipse_Admob_Android Linearlayout_Processing - Fatal编程技术网

&引用;无法解析linearLayout或它不是字段;使用谷歌针对Android的AdMob指令

&引用;无法解析linearLayout或它不是字段;使用谷歌针对Android的AdMob指令,android,eclipse,admob,android-linearlayout,processing,Android,Eclipse,Admob,Android Linearlayout,Processing,我试图在一个小时内找到问题的解决方案,我发现了一些与我类似的问题,但我不知道如何解决 我在为Android开发一个带有处理功能的应用程序,我想尝试AdMob(现在只是为了学习),所以我在网上按照说明操作,现在我被卡住了 为了在应用程序中添加广告,我按照谷歌的指示添加了Play Service的SDK并添加了横幅,但我被困在这里: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstan

我试图在一个小时内找到问题的解决方案,我发现了一些与我类似的问题,但我不知道如何解决

我在为Android开发一个带有处理功能的应用程序,我想尝试AdMob(现在只是为了学习),所以我在网上按照说明操作,现在我被卡住了

为了在应用程序中添加广告,我按照谷歌的指示添加了Play Service的SDK并添加了横幅,但我被困在这里:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.activity_main);
        initPdService();

        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("ca-app-pu....83399");

        // Add the AdView to the view hierarchy. The view will have no size
        // until the ad is loaded.
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
        // .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        // .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
                .build();

        // Start loading the ad in the background.
        adView.loadAd(adRequest);

    }
问题是,它给了我“线性布局无法解决或它不是一个字段”,我不知道如何解决。我认为问题出在
findViewById(R.id.linearLayout)
,因为错误在“linearLayout”而不是“linearLayout”

我相信很多人都会发现这个问题,所以我认为这是一个普遍的问题。我已经添加了
import android.widget.LinearLayout在草图的顶部,所以我不知道问题出在哪里

其他信息:它的目标是Android SDK 19,因为我知道Play服务至少需要API级别13

编辑: 这是我的[旧]活动_main.xml,找到的是/res/layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <android.support.v7.widget.Space
        android:id="@+id/space1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/adView"
        android:layout_marginTop="208dp"
        android:layout_toRightOf="@+id/adView" />

    <View
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

编辑2: 这是我的新活动_main.xml,带有linearLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal" >

        <android.support.v7.widget.Space
        android:id="@+id/space1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/adView"
        android:layout_marginTop="208dp"
        android:layout_toRightOf="@+id/adView" />

    <View
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />
 </LinearLayout>

</RelativeLayout>

您需要设置内容视图:

setContentView(R.layout.activity_main);
你已经注释掉了。您是否有包含id为LinearLayout的LinearLayout的xml文件“activity_main.xml”

如果没有id为LinearLayout的LinearLayout,则需要添加一个。否则,它会试图找到一个不存在的视图(通过id!)。例如:

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal" >
...
 </LinearLayout>

...

您的问题是,您将处理作为Android SDK上的一个库使用,而它无法访问布局文件,因为在处理过程中,您通过编程方式创建屏幕-对于熟悉Android而不进行处理的人来说,这类似于一个大类

实际的编译错误是生成的R.java文件找不到压缩的资源

我从未尝试过添加AdMob,但实际上我认为您的问题在于,您需要以编程方式实例化LinearLayout,而不是通过XML—同样,您无法通过PDE访问它

编辑:

  • 刚刚注意到您正在使用Eclipse(和LibPd)。。。好的,这样你就可以得到一个布局了
  • 能否显示将处理导入活动的代码
如果我取消注释该行,错误仍然存在。我通过添加activity_main.xml编辑了这篇文章,但是LinearLayout没有id,这是你的问题!您需要一个id linearLayout,以便查找id linearLayout.:)谢谢,我怎么做?很抱歉,我是Android开发新手,我正在开发我的第一个应用程序,添加了Android处理功能——看看这是否有帮助。太好了!成功了谢谢:D现在我有另一个问题。。。我只有一个白色屏幕(带有广告横幅):\n事实上,现在我有一个顶部带有广告横幅的白色屏幕。。。为了导入处理,我复制了项目库文件夹中的Processing-core.jar,然后扩展PApplet<代码>公共类MainActivity扩展了PApplet{public int sketchWidth(){return displayWidth;}public int sketchHeight(){return displayHeight;}public String sketchRenderer(){return OPENGL;}public void setup(){//stuffs}public void draw(){//stuffs}}