“找不到符号ActionBarActivity”下的Andr​​oid开发教程? [英] 'cannot find symbol ActionBarActivity' following Android Development Tutorial?

查看:1322
本文介绍了“找不到符号ActionBarActivity”下的Andr​​oid开发教程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我下面这个教程,用崇高的一个文本编辑器和编译一切从控制台。

So I am following this tutorial, using Sublime as a text editor and compiling everything from console.

全是工作不错,但是当我们来到了一部分,你应该做次活动。他们用Eclipse来自动生成它,并告诉我将其粘贴下来,所以我做到了。

All was working good, but when we came to the part where you are supposed to make second Activity. They used Eclipse to autogenerate it and told me to paste it down, so I did.

下面是我的code(我加了一些入口和包在一开始,它修复了一些问题)

Here is my code (I added some imports and package at the beginning, it fixes some problems)

package pl.qnsi.myfirstapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.MenuItem;


public class DisplayMessageActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    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;
        }
    }
}

而从控制台的错误日志

[qnsi@archie MyFirstApp]$ ant debug
Buildfile: /home/qnsi/code/Apps/learning/MyFirstApp/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.6.4
 [checkenv] Installed at /opt/android-sdk

-setup:
     [echo] Project Name: MyFirstApp
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.1.0
     [echo] Resolving Build Target for MyFirstApp...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
     [echo] ----------
     [echo] Resolving Dependencies for MyFirstApp...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] No changes in the AndroidManifest files.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] No changed resources. R.java and Manifest.java untouched.
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
    [javac] Compiling 3 source files to /home/qnsi/code/Apps/learning/MyFirstApp/bin/classes
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:12: error: cannot find symbol
    [javac] public class DisplayMessageActivity extends ActionBarActivity {
    [javac]                                             ^
    [javac]   symbol: class ActionBarActivity
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:40: error: cannot find symbol
    [javac]     public static class PlaceholderFragment extends Fragment {
    [javac]                                                     ^
    [javac]   symbol:   class Fragment
    [javac]   location: class DisplayMessageActivity
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:45: error: cannot find symbol
    [javac]         public View onCreateView(LayoutInflater inflater, ViewGroup container,
    [javac]                                  ^
    [javac]   symbol:   class LayoutInflater
    [javac]   location: class PlaceholderFragment
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:45: error: cannot find symbol
    [javac]         public View onCreateView(LayoutInflater inflater, ViewGroup container,
    [javac]                                                           ^
    [javac]   symbol:   class ViewGroup
    [javac]   location: class PlaceholderFragment
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:45: error: cannot find symbol
    [javac]         public View onCreateView(LayoutInflater inflater, ViewGroup container,
    [javac]                ^
    [javac]   symbol:   class View
    [javac]   location: class PlaceholderFragment
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:16: error: cannot find symbol
    [javac]         super.onCreate(savedInstanceState);
    [javac]         ^
    [javac]   symbol:   variable super
    [javac]   location: class DisplayMessageActivity
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:17: error: cannot find symbol
    [javac]         setContentView(R.layout.activity_display_message);
    [javac]                                ^
    [javac]   symbol:   variable activity_display_message
    [javac]   location: class layout
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:21: error: cannot find symbol
    [javac]                 .add(R.id.container, new PlaceholderFragment()).commit();
    [javac]                          ^
    [javac]   symbol:   variable container
    [javac]   location: class id
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:20: error: cannot find symbol
    [javac]             getSupportFragmentManager().beginTransaction()
    [javac]             ^
    [javac]   symbol:   method getSupportFragmentManager()
    [javac]   location: class DisplayMessageActivity
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:14: error: method does not override or implement a method from a supertype
    [javac]     @Override
    [javac]     ^
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:31: error: cannot find symbol
    [javac]         if (id == R.id.action_settings) {
    [javac]                       ^
    [javac]   symbol:   variable action_settings
    [javac]   location: class id
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:34: error: cannot find symbol
    [javac]         return super.onOptionsItemSelected(item);
    [javac]                ^
    [javac]   symbol:   variable super
    [javac]   location: class DisplayMessageActivity
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:25: error: method does not override or implement a method from a supertype
    [javac]     @Override
    [javac]     ^
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:47: error: cannot find symbol
    [javac]               View rootView = inflater.inflate(R.layout.fragment_display_message,
    [javac]               ^
    [javac]   symbol:   class View
    [javac]   location: class PlaceholderFragment
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:47: error: cannot find symbol
    [javac]               View rootView = inflater.inflate(R.layout.fragment_display_message,
    [javac]                                                        ^
    [javac]   symbol:   variable fragment_display_message
    [javac]   location: class layout
    [javac] /home/qnsi/code/Apps/learning/MyFirstApp/src/pl/qnsi/myfirstapp/DisplayMessageActivity.java:44: error: method does not override or implement a method from a supertype
    [javac]         @Override
    [javac]         ^
    [javac] 16 errors

BUILD FAILED
/opt/android-sdk/tools/ant/build.xml:720: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:734: Compile failed; see the compiler error output for details.

Total time: 1 second

我GOOGLE了一些答案,但大部分的错误是固定的通过导入我已经导入库。我从来没有见过一个问题,重载方法或没有找到超级方法。 我无言以对该怎么做。

I googled for some answers but most of the errors were fixed by importing the libraries I already imported. I never saw a problem with overloading method or not finding super method. I am clueless what to do.

推荐答案

如果你使用Eclipse在 DisplayMessageActivity.java 添加然后将其从派生ActionBarActivity ,并增加了在所有支持code与该给你。

If you use Eclipse to add in DisplayMessageActivity.java then it derives from ActionBarActivity and adds in all the support code related to that for you.

然而,如果你正在使用命令行工具下面的教程,那么 ActionBarActivity 东西是尚未设定。他们得到了在本教程的下一部分。

However if you are following the tutorial using commandline tools, then the ActionBarActivity stuff is not set up yet. They get to that in the next part of the tutorial.

相反,你可以使用下面的$ C $下 DisplayMessageActivity.java

Instead, you can use the following code for DisplayMessageActivity.java:

package com.example.yourname;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.EditText;
import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    // Get the message from the intent
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    // Create the text view
        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        setContentView(textView);

    }
}

您还需要添加到 MainActivity.java 当你正在做的一步开始第二次活动:

You will also need to add into MainActivity.java when you are doing the step "Start the Second Activity":

import android.view.View;

这篇关于“找不到符号ActionBarActivity”下的Andr​​oid开发教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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