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

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

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

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

Android Studio

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

Q&A

解決済

1回答

491閲覧

Rエラーが直りません

agaga

総合スコア7

Java

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

Android Studio

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

0グッド

0クリップ

投稿2017/11/24 09:45

android studioで高速フーリエ変換のライブラリを使って最大振幅数を表示するアプリをつくっえいます。ですが、Rエラーが消えずコンパイルができません。出回ってるエラー対策はすべて試してみましたが改善されず下記のエラーがでます。一応xmlも確認したのですが誤字などもないです。
Error:(2) No resource identifier found for attribute 'layout_behavior' in package 'com.example.android.sample.oto'

mainActivity

省略

public class MainActivity extends AppCompatActivity
implements Runnable, View.OnClickListener, Handler.Callback {
private static final String TAG = "SNC";

private static final int SAMPLE_RATE = 44100; private static final short THRESHOLD_AMP = 0x00ff; private static final int MSG_RECORD_START = 100; private static final int MSG_RECORD_END = 110; private static final int MSG_FREQ_PEAK = 120; private static final int MSG_SILENCE = 130; private Handler mHandler; private AudioRecord mAudioRecord = null; private Button mButton01; private TextView mTextView02; private boolean mInRecording = false; private boolean mStop = false; private int mBufferSizeInShort; private short mRecordBuf[]; private DoubleFFT_1D mFFT; private double mFFTBuffer[]; private int mFFTSize; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); mHandler = new Handler(this); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mButton01 = (Button)findViewById(R.id.button01); mButton01.setOnClickListener(this); mTextView02 = (TextView)findViewById(R.id.textView02); int bufferSizeInBytes = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); mBufferSizeInShort = bufferSizeInBytes / 2; // 録音用バッファ mRecordBuf = new short[mBufferSizeInShort]; // FFT 処理用 mFFTSize = mBufferSizeInShort; mFFT = new DoubleFFT_1D(mFFTSize); mFFTBuffer = new double[mFFTSize]; mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSizeInBytes); } @Override public void onStop() { super.onStop(); Log.d(TAG, "onStop"); } @Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); mStop = true; try { Thread.sleep(2000); } catch (InterruptedException e) { } if (mAudioRecord != null) { if (mAudioRecord.getRecordingState() != AudioRecord.RECORDSTATE_STOPPED) { Log.d(TAG, "cleanup mAudioRecord"); mAudioRecord.stop(); } mAudioRecord = null; } } @Override public void onClick(View v) { if (v == (View)mButton01) { // 集音開始 or 終了 if (!mInRecording) { mInRecording = true; new Thread(this).start(); } else { mInRecording = false; } } return; } @Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_RECORD_START: Log.d(TAG, "MSG_RECORD_START"); mButton01.setText("終了"); break; case MSG_RECORD_END: Log.d(TAG, "MSG_RECORD_END"); mButton01.setText("開始"); break; case MSG_FREQ_PEAK: mTextView02.setText(Integer.toString(msg.arg1) + " Hz"); break; case MSG_SILENCE: mTextView02.setText(""); break; } return true; } @Override public void run() { boolean bSilence = false; mHandler.sendEmptyMessage(MSG_RECORD_START); // 集音開始 mAudioRecord.startRecording(); while (mInRecording && !mStop) { mAudioRecord.read(mRecordBuf, 0, mBufferSizeInShort); bSilence = true; for (int i = 0; i < mBufferSizeInShort; i++) { short s = mRecordBuf[i]; if (s > THRESHOLD_AMP) { bSilence = false; } } if (bSilence) { // 静寂 mHandler.sendEmptyMessage(MSG_SILENCE); continue; } int freq = doFFT(mRecordBuf); Message msg = new Message(); msg.what = MSG_FREQ_PEAK; msg.arg1 = freq; mHandler.sendMessage(msg); } // 集音終了 mAudioRecord.stop(); mHandler.sendEmptyMessage(MSG_RECORD_END); } private int doFFT(short[] data) { for (int i = 0; i < mFFTSize; i++) { mFFTBuffer[i] = (double)data[i]; } // FFT 実行 mFFT.realForward(mFFTBuffer); // 処理結果の複素数配列から各周波数成分の振幅値を求めピーク分の要素番号を得る double maxAmp = 0; int index = 0; for (int i = 0; i < mFFTSize/2; i++) { double a = mFFTBuffer[i*2]; // 実部 double b = mFFTBuffer[i*2 + 1]; // 虚部 // a+ib の絶対値 √ a^2 + b^2 = r が振幅値 double r = Math.sqrt(a*a + b*b); if (r > maxAmp) { maxAmp = r; index = i; } } // 要素番号・サンプリングレート・FFT サイズからピーク周波数を求める return index * SAMPLE_RATE / mFFTSize; }

}

activity main

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.android.sample.oto.MainActivity">

<android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

content main

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" 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" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.android.sample.oto.MainActivity" tools:showIn="@layout/activity_main">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Peak Frequency" android:id="@+id/textView01" android:gravity="center" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start" android:id="@+id/button01" android:layout_below="@+id/textView01" android:layout_alignStart="@+id/textView01" android:layout_marginTop="20dp" android:layout_alignEnd="@+id/textView01" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text=" " android:id="@+id/textView02" android:layout_below="@+id/button01" android:layout_marginTop="20dp" android:layout_centerHorizontal="true" />
</RelativeLayout>

JTransformsのライブラリを入れてます。

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

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

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

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

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

guest

回答1

0

ベストアンサー

build.gradle (Module:app) の設定抜けではないでしょうか。

例:

compile 'com.android.support:design:22.2.0'

※バージョンは利用しているものに合わせて下さい。

参考:

Android Developers Blog / Android Design Support Library
Available now! を参照

Stackoverflow - No resource identifier found for attribute 'layout_behavior' in package

layout_behavior に関連しているクラス:
Android developer - AppBarLayout

投稿2017/11/24 10:16

toris-birds

総合スコア122

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問