谷歌Android教程 - 不编译 [英] Google Android tutorial - not compiling

查看:170
本文介绍了谷歌Android教程 - 不编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的一切,就像在本教程中指出:
谷歌的android基础教程
尽管一切都被刚刚做了描述的那样,在code拒绝与3个错误进行编译。貌似家伙写turorial忘了提什么这些事情,在那里/我该如何定义它们。

I did everything just as stated in this tutorial: google android basic tutorial and despite everything being done just as described, the code refuses to compile with 3 errors. Looks like the guys writing the turorial forgot to mention what are those things and where/how do I define them.

的错误,我得到:

Error:(24, 68) error: cannot find symbol variable container
Error:(36, 23) error: cannot find symbol variable action_settings
Error:(46, 54) error: cannot find symbol variable fragment_display_message

无论是3场的任何地方都定义(也许库之一是错了吗?)
有问题的文件是:

Neither of the 3 fields are defined anywhere (Perhaps one of the libraries is wrong?) The file in question is:

package com.example.asteroth.first;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.R;

public class DisplayMessageActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);
        setContentView(textView);
//        setContentView(R.layout.activity_display_message);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
        }

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public static class PlaceholderFragment extends Fragment {
        public PlaceholderFragment() { }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_display_message, container, false);
            return rootView;
        }
    }
}

我使用Android的工作室我刚刚下载,并没有从这样一个问题,搜索或类似的问题点的问题,所以我怀疑教程的作者忘了提一些未成年人。我见过的建议,把容器作为XML文件中的一个新的ID,但无济于事。

I am using Android Studio I just downloaded and no question from search or Similar Questions points at the problem like this one, hence I suspect authors of tutorial forgot to mention something minor. I've seen suggestion to place the "container" as a new ID in one of the XML files, but to no avail.

编辑:
<一href=\"http://stackoverflow.com/questions/24382959/cannot-find-symbol-actionbaractivity-following-android-development-tutorial\">'cannot找到符号ActionBarActivity'以下的Andr​​oid开发教程?
这篇文章提出一个解决方案,但是它改变ActionBarActivity只是活动是从什么教程使用,我不知道截然不同怎样严重的后果会是引起

'cannot find symbol ActionBarActivity' following Android Development Tutorial? This post suggest a solution, however it changes ActionBarActivity to just Activity which is very different from what the tutorial uses and I don't know how serious repercussions would it cause

EDIT2:
搜走的问题:
    进口android.R //导致action_settings错误
    集装箱缺少//不得不给它的XML文件添加为一个id
    xml文件命名错//如果我得到了正确的,我仍然在等待某人经历了澄清,但似乎是一个教程,然后在XML文件中使用不同的名称一个java的code引用

Problems found and removed: import android.R //causes action_settings error container missing //had to add it in the xml file as an id xml file named wrong //If I got that correctly, I'm still waiting for someone experienced to clarify, but seems like the tutorial used different name for the xml file then the one that the java code references

剩下的问题就是与此类似
<一href=\"http://stackoverflow.com/questions/25934917/cannot-resolve-method-placeholderfragment-error\">Cannot解决方法placeholderfragment错误
不过,我都扩展片段,包括android.app.Fragment作为可以在包含的文件中可以看出。

Remaining problem is similar to this one Cannot resolve method placeholderfragment error however, I both extend Fragment and include android.app.Fragment as can be seen in the included file.

推荐答案

我试过相同的教程,这里是我如何固定我的错误:

I tried the same tutorial and here is how I fixed my errors:

R.id.container不能得到解决的错误

我不得不进口android.support.v4.app.Fragment来解决这个问题,并添加机器人:ID =@ + ID /集装箱到RelativeLayout的部分我activity_display_message.xml文件

I had to import android.support.v4.app.Fragment to fix this problem and add android:id = "@+id/container" to the RelativeLayout section in my activity_display_message.xml file.

fragment_display_message不能得到解决的错误

更改R.layout.fragment_display_message,而不是R.layout.activity_display_message。没有必要创建用于fragment_display_message一个新的xml文件

Change R.layout.fragment_display_message to R.layout.activity_display_message instead. There is no need for creating a new xml file for fragment_display_message.

这应该可以解决这两个错误。

This should fix these two errors.

但你可能会更好,如果你注释掉如果(savedInstanceState ............声明,否则,一旦你尝试运行它,如果它不给你你的程序会崩溃任何错误。

But you would probably be better off if you comment out the if(savedInstanceState............ statement as otherwise your program would crash once you try to run it if it doesn't give you any errors.

您onCreate方法应该是这样的:

Your onCreate method should look like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_display_message);
    Intent intent=getIntent();
    String message=intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    TextView textView=new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    setContentView(textView);

    /*if (savedInstanceState==null){
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }*/
}

这篇关于谷歌Android教程 - 不编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆