Я пытаюсь создать аудио активности захвата, так что я скопировал класс от андроида документации, которая выглядит, как этотИспользование пользовательских объектов в XML
package com.android.audiorecordtest;
import android.app.Activity;
import android.widget.LinearLayout;
import android.os.Bundle;
import android.os.Environment;
import android.view.ViewGroup;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.Context;
import android.util.Log;
import android.media.MediaRecorder;
import android.media.MediaPlayer;
import java.io.IOException;
public class AudioRecordTest extends Activity
{
private static final String LOG_TAG = "AudioRecordTest";
private static String mFileName = null;
private RecordButton mRecordButton = null;
private MediaRecorder mRecorder = null;
private PlayButton mPlayButton = null;
private MediaPlayer mPlayer = null;
private void onRecord(boolean start) {
if (start) {
startRecording();
} else {
stopRecording();
}
}
private void onPlay(boolean start) {
if (start) {
startPlaying();
} else {
stopPlaying();
}
}
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
}
private void stopPlaying() {
mPlayer.release();
mPlayer = null;
}
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
class RecordButton extends Button {
boolean mStartRecording = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onRecord(mStartRecording);
if (mStartRecording) {
setText("Stop recording");
} else {
setText("Start recording");
}
mStartRecording = !mStartRecording;
}
};
public RecordButton(Context ctx) {
super(ctx);
setText("Start recording");
setOnClickListener(clicker);
}
}
class PlayButton extends Button {
boolean mStartPlaying = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onPlay(mStartPlaying);
if (mStartPlaying) {
setText("Stop playing");
} else {
setText("Start playing");
}
mStartPlaying = !mStartPlaying;
}
};
public PlayButton(Context ctx) {
super(ctx);
setText("Start playing");
setOnClickListener(clicker);
}
}
public AudioRecordTest() {
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout ll = new LinearLayout(this);
mRecordButton = new RecordButton(this);
ll.addView(mRecordButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
mPlayButton = new PlayButton(this);
ll.addView(mPlayButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
setContentView(ll);
}
@Override
public void onPause() {
super.onPause();
if (mRecorder != null) {
mRecorder.release();
mRecorder = null;
}
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}
Я переименовал деятельность в MicrophoneActivity и я положил его в пакет вызванная деятельность
Теперь я хочу вместо программирования в макете я хочу использовать xml-файл.
Так что я редактировал OnCreate, чтобы выглядеть следующим образом
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_microphone);
mRecordButton = (RecordButton) findViewById(R.id.microphone);
}
И в моей странице XML Я пытаюсь создать RecordButton с микрофоном ид. Что-то вроде этого
<com.heyprestoapp.heypresto.activity.MicrophoneActivity.RecordButton
android:id="@+id/microphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"/>
Теперь, когда я пытаюсь запустить приложение аварии со следующим выходом
E/AndroidRuntime: фатальная ошибка: основной процесс: com.heyprestoapp.heypresto, PID: 22471 Java. lang.RuntimeException: Невозможно начать деятельность ComponentInfo {com.heyprestoapp.heypresto/com.heyprestoapp.heypresto.activity.MicrophoneActivity}: android.view.InflateException: Binary XML файл строка # 18: Binary XML строка файла # 18 : Ошибка раздувания класса com.heyprestoapp.heypresto.activity.MicrophoneActivity.RecordButton в android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3319) на android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415) в android.app. ActivityThread.access $ 1100 (ActivityThread.java:229) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1821) на android.os.Handler.dispatchMessage (Handler.java:102) на android.os .Looper.loop (Looper.java:148) на android.app.ActivityThread.main (ActivityThread.java:7325) на java.lang.reflect.Method.invoke (собственный метод) на com.android.internal. os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120) Вызвано: android.view.InflateException: двоичная строка XML-файла # 18: Двоичная строка XML-файла # 18: ошибка раздувания класса com. heyprestoapp.heypresto.activity.MicrophoneActivity.RecordButton в android.view.LayoutInflater.inflate (LayoutInflater.java:551) на android.view.LayoutInflater.inflate (LayoutInflater.java:429) в android.view.LayoutInflater.inflate (LayoutInflater.java:380) на com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:479) на android.app.Activity.setContentView (Activity.java:2400) на com.heyprestoapp.heypresto .activity.MicrophoneActivity.onCreate (MicrophoneActivity.java:149) на android.app.Ac tivity.performCreate (Activity.java:6904) на android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136) на android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266) на android.app.ActivityThread. handleLaunchActivity (ActivityThread.java:3415) at android.app.ActivityThread.access $ 1100 (ActivityThread.java:229) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1821) at android.os.Handler .dispatchMessage (Handler.java:102) на android.os.Looper.loop (Looper.java:148) на android.app.ActivityThread.main (ActivityThread.java:7325) at java.lang.reflect.Method.invoke (собственный метод) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1230) в com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Вызванный: android.view.InflateException: Binary XML файл строка # 18: Ошибка при наполнении класса com.heyprestoapp.heypresto.activity. MicrophoneActivity.RecordButton в android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:788) на android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:716) в android.view.LayoutInflater.rInflate (LayoutInflater.java:847) at androi d.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810) на android.view.LayoutInflater.inflate (LayoutInflater.java:527) на android.view.LayoutInflater.inflate (LayoutInflater.java:429) на android. view.LayoutInflater.inflate (LayoutInflater.java:380) at com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:479) at android.app.Activity.setContentView (Activity.java:2400) at com.heyprestoapp.heypresto.activity.MicrophoneActivity.onCreate (MicrophoneActivity.java:149) на android.app.Activity.performCreate (Activity.java:6904) на android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136) на android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415) at android.app.ActivityThread.access $ 1100 (ActivityThread.java:229) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1821) на android.os.Handler.dispatchMessage (Handler.java:102) на android.os.Looper.loop (Looper.java:148) на android.app.ActivityThread.main (ActivityThread .java: 7325) at java.lang.reflect.Method.invoke (собственный метод) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1230) at com.android.internal. os.ZygoteInit.main (ZygoteInit.java:1120)
Причиненный: j ava.lang.ClassNotFoundException: не нашел класс "com.heyprestoapp.heypresto.activity.MicrophoneActivity.RecordButton" по пути: DexPathList [[zip-файл "/data/app/com.heyprestoapp.heypresto-2/base .apk "], nativeLibraryDirectories = [/ data/app/com.heyprestoapp.heypresto-2/lib/arm, /vendor/lib,/system/lib]] в dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java : 56) на java.lang.ClassLoader.loadClass (ClassLoader.java:511) на java.lang.ClassLoader.loadClass (ClassLoader.java:469) на android.view.LayoutInflater.createView (LayoutInflater.java:595) на android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:776) на android.view.LayoutInflater.crea teViewFromTag (LayoutInflater.java:716) на android.view.LayoutInflater.rInflate (LayoutInflater.java:847) на android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:810) в android.view.LayoutInflater.inflate (LayoutInflater.java:527) на android.view.LayoutInflater.inflate (LayoutInflater.java:429) на android.view.LayoutInflater.inflate (LayoutInflater.java:380) на com.android.internal.policy.PhoneWindow. setContentView (PhoneWindow.java:479) на android.app.Activity.setContentView (Activity.java:2400) на com.heyprestoapp.heypresto.activity.MicrophoneActivity.onCreate (MicrophoneActivity.java:149) на android.app. Activity.performCreate (активность.Java: 6904) на android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136) на android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266) на android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 3415) на android.app.ActivityThread.access $ 1100 (ActivityThread.java:229) на android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1821) на android.os.Handler.dispatchMessage (Handler.java : 102) на android.os.Looper.loop (Looper.java:148) на android.app.ActivityThread.main (ActivityThread.java:7325) на java.lang.reflect.Method.invoke (собственный метод) at com.android.internal.os.ZygoteInit $ MethodAn dArgsCaller.run (ZygoteInit.java:1230) в com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Подавленные: java.lang.ClassNotFoundException: Не нашли класс «com.heyprestoapp .heypresto.activity.MicrophoneActivity.RecordButton " по пути: DexPathList [[DEX файл " /data/data/com.heyprestoapp.heypresto/files/instant-run/dex/slice-support-annotations-24.1.1_f2d68394ace2648d246e9f3a6f79e1c800e15e57-classes .dex " Dex файл "/data/data/com.heyprestoapp.heypresto/files/instant-run/dex/slice-smack-tcp-4.1.0_831e36ba6f57de45ead9e83b8319b14f30ea801e-classes.dex", Dex файл "/данные /data/com.heyprestoapp.heypresto/files/instant-run/dex/slice-smack-sasl-provided-4.1.3_396a290b83 a0453d3a97b95e8c362f0a61ef9c13-classes.dex»Декс файл "/data/data/com.heyprestoapp.heypresto/files/instant-run/dex/slice-smack-resolver-minidns-4.1.3_427e3bfc74840e180f88b6f0e4b12b2c05808d12-classes.dex", Dex файл "/data/data/com.heyprestoapp.heypresto/files/instant-run/dex/slice-smack-im-4.1.3_7ebbb2471a6968d543236c3d4074f7a01c7a90a1-classes.dex", файл dex "/data/data/com.heyprestoapp.hey
написать отзыв для RecordButton. – SaravInfern
Этот класс существует в вашем пакете?
estoke
вы должны использовать это вместо: com.android.audiorecordtest.RecordButton в вашем xml – estoke