質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

3732閲覧

Element must be declared、can not resolve symbol action_voice_inputなどのエラーが出ます。

edoooooo

総合スコア476

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

1グッド

0クリップ

投稿2016/05/24 11:19

編集2016/05/25 10:40

menu_chat.xmlです。

java

1<item android:id="@+id/action_voice_input" 2android:title="@string/action_voice_input" 3android:ico="@drawable/ic_action_voice_input" 4app:showAsAction="ifRoom"/>

itemの部分に、Element must be declaredとエラーが出ます。
終了タグに問題があるのかと思ったのですが、違いました。

ChatActivityです。(java)

java

1 @Override 2 public boolean onOptionsItemSelected(MenuItem item) { 3 // Handle action bar item clicks here. The action bar will 4 // automatically handle clicks on the Home/Up button, so long 5 // as you specify a parent activity in AndroidManifest.xml. 6 int id = item.getItemId(); 7 8 //noinspection SimplifiableIfStatement 9 if (id == R.id.action_voice_input) { 10 11 Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 12 startActivityForResult(intent,0); 13 return true; 14 } 15 16 return super.onOptionsItemSelected(item); 17 }

can not resolve symbol action_voice_input とでます。
File → Invalidate Caches / Restart...のような対応をしたのですが、ダメでした。

コンソールです。

java

1Error:(4) Error parsing XML: unbound prefix 2Error:Execution failed for task ':chatapplication:processDebugResources'. 3> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/taichi/Library/Android/sdk/build-tools/23.0.0/aapt'' finished with non-zero exit value 1

finished with non-zero exit valueへの対策として、
File → Settings より設定画面を開き、Build, Execution, Deployment → Compiler → Java Compiler → Project bytecode version の値を空白から 1.7 に変更してからコンパイルしたのですが、結果は変わりませんでした。

Androidアプリ開発の教科書という本でやっているのですが、コードを写してもうまくいかず、英語と日本語に対応するコードは、飛ばしました。バージョンの問題でしょうか?どうぞよろしくお願いします。

今は、音声入力をつけようとしています。どうぞよろしくお願いします。

//このしたの2つのコードをついかしました。
activity_game.xml

java

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.design.widget.CoordinatorLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 6 android:layout_height="match_parent" android:fitsSystemWindows="true" 7 tools:context=".GameActivity"> 8 9 <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" 10 android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> 11 12 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 13 android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" 14 android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> 15 16 </android.support.design.widget.AppBarLayout> 17 18 <include layout="@layout/content_game" /> 19 20 <android.support.design.widget.FloatingActionButton android:id="@+id/fab" 21 android:layout_width="wrap_content" android:layout_height="wrap_content" 22 android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" 23 android:src="@android:drawable/ic_dialog_email" /> 24 25</android.support.design.widget.CoordinatorLayout> 26

content_game.xml

java

1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 5 android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 6 android:paddingRight="@dimen/activity_horizontal_margin" 7 android:paddingTop="@dimen/activity_vertical_margin" 8 android:paddingBottom="@dimen/activity_vertical_margin" 9 app:layout_behavior="@string/appbar_scrolling_view_behavior" 10 tools:showIn="@layout/activity_game" tools:context=".GameActivity"> 11 12 <TextView android:text="Hello World!" android:layout_width="wrap_content" 13 android:layout_height="wrap_content" /> 14</RelativeLayout> 15
recode👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

itemは1番の親には持ってこれなかったと思うのですが。
xml全体を提示していただけないでしょうか?

投稿2016/05/24 14:00

swordone

総合スコア20651

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

edoooooo

2016/05/25 11:10 編集

xmlのコードを追加いたしました。どうぞ宜しくお願いします。 activity_game.xmlとcontent_game.xmlを追加しました。
swordone

2016/05/25 13:31

itemが属しているxmlを見たかったのですが…
edoooooo

2016/05/31 09:33 編集

申し訳ありません、返信が遅くなり失礼いたしました。 すべての問題が本通りで動かず、アドバイスをいただきやっと動くという状態のため、 インストールに不備があったのではと感じ、色々とやり直したところで、返信を忘れていました。 コードもサンプルコードも最初から実行して行ない、一度整理、したいと思います。 ありがとうございました。また同じような問題が発生しましたら、質問させていただきます。ありがとうございました。 
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問