Android 未找到与给定名称匹配的资源(位于值为“@drawable/icon”的“icon”)
我是android新手,我正在尝试制作一个可以分析噪音水平的应用程序,我发现了一个有用的资源,不幸的是,我得到了上述错误。我已附上我所有的文件,因此,任何线索来修复这将是非常感谢 这是清单文件Android 未找到与给定名称匹配的资源(位于值为“@drawable/icon”的“icon”),android,android-audiorecord,Android,Android Audiorecord,我是android新手,我正在尝试制作一个可以分析噪音水平的应用程序,我发现了一个有用的资源,不幸的是,我得到了上述错误。我已附上我所有的文件,因此,任何线索来修复这将是非常感谢 这是清单文件 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.prabalgupt
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prabalgupta.noisealert"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name="com.androidexample.noisealert.NoiseAlert"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
SoundLevelView.java
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
class SoundLevelView extends View {
private Drawable mGreen;
private Drawable mRed;
private Paint mBackgroundPaint;
private int mHeight;
private int mWidth;
private int mThreshold = 0;
private int mVol = 0;
public SoundLevelView(Context context, AttributeSet attrs) {
super(context, attrs);
mGreen = context.getResources().getDrawable(
R.drawable.greenbar);
mRed = context.getResources().getDrawable(
R.drawable.redbar);
mWidth = mGreen.getIntrinsicWidth();
setMinimumWidth(mWidth*10);
mHeight = mGreen.getIntrinsicHeight();
setMinimumHeight(mHeight);
//Used to paint canvas background color
mBackgroundPaint = new Paint();
mBackgroundPaint.setColor(Color.BLACK);
}
public void setLevel(int volume, int threshold) {
if (volume == mVol && threshold == mThreshold) return;
mVol = volume;
mThreshold = threshold;
// invalidate Call onDraw method and draw voice points
invalidate();
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawPaint(mBackgroundPaint);
for (int i=0; i<= mVol; i++) {
Drawable bar;
if (i< mThreshold)
bar = mGreen;
else
bar = mRed;
bar.setBounds((10-i)*mWidth, 0, (10-i+1)*mWidth, mHeight);
bar.draw(canvas);
}
}
}
活动\u noise\u alert.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textStyle="bold"
android:text="stopped"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
<com.androidexample.noisealert.SoundLevelView
android:id="@+id/volume"
android:layout_width="230sp"
android:layout_height="60sp"
/>
</LinearLayout>
</RelativeLayout>
在清单文件中,您试图为应用程序设置一个图标 通过此代码,android:icon=@drawable/icon 这意味着您应该在res/drawable文件夹中放置一个icon.png img。否则,将icon.png img放置在drawable文件夹中,您的问题将得到解决。img文件名不能强制为icon.png,它可以是任何名称,如ic_launcher.png。。。。。然后,您需要像下面这样更改清单文件:icon=@drawable/ic_launcher 但img将是png格式
谢谢您的drawable文件夹中似乎缺少一个名为icon.png的文件。请尝试发布一个最小的示例-我们复制您的问题所需的最小代码量。你发布的内容需要做很多工作,这会使你的问题更难回答。
import java.io.IOException;
import android.media.MediaRecorder;
public class SoundMeter {
// This file is used to record voice
static final private double EMA_FILTER = 0.6;
private MediaRecorder mRecorder = null;
private double mEMA = 0.0;
public void start() {
if (mRecorder == null) {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
try {
mRecorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mRecorder.start();
mEMA = 0.0;
}
}
public void stop() {
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
public double getAmplitude() {
if (mRecorder != null)
return (mRecorder.getMaxAmplitude()/2700.0);
else
return 0;
}
public double getAmplitudeEMA() {
double amp = getAmplitude();
mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
return mEMA;
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textStyle="bold"
android:text="stopped"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
<com.androidexample.noisealert.SoundLevelView
android:id="@+id/volume"
android:layout_width="230sp"
android:layout_height="60sp"
/>
</LinearLayout>
</RelativeLayout>