Написал такой код в Android studio, где издается звук при нажатии на картинку, но при клике на изображение в эмуляторе приложение вылетает. Смотрел логи, но ничего путного в интернете по этому поводу не нашел. Буду крайне рад за помощь
package com.example.project_1;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
private ImageView img1, img2;
private MediaPlayer sound1, sound2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img1=(ImageView)findViewById(R.id.image1);
img2=(ImageView)findViewById(R.id.image2);
sound1=MediaPlayer.create(this, R.raw.sn1);
sound2=MediaPlayer.create(this, R.raw.sn2);
imageClick();
}
public void imageClick() {
img1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SoundPlay(sound1);
}
}
);
img2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SoundPlay(sound2);
}
}
);
}
public void SoundPlay(MediaPlayer allsounds) {
allsounds.start();
}
}
а вот и часть лога из error, ибо строк слишком(!) много:
2019-06-01 13:58:26.684 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 13:59:08.565 1869-1975/? E/ClipboardService: Denying clipboard access to com.google.android.as, application is not in focus neither is the IntelligeService for user 0
2019-06-01 13:59:26.696 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 13:59:26.697 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:00:26.718 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:00:26.719 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:01:26.737 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:01:26.737 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:02:26.752 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:02:26.752 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:03:26.760 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:03:26.761 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 13:59:13.317 1869-1975/? E/ClipboardService: Denying clipboard access to com.google.android.as, application is not in focus neither is the IntelligeService for user 0
2019-06-01 14:03:44.845 12244-12244/? E/id.partnersetu: Not starting debugger since process cannot load the jdwp agent.
2019-06-01 14:03:44.855 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:04:18.086 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:04:26.761 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:04:26.761 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:05:26.820 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:05:26.820 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:05:41.570 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:05:41.584 12270-12270/? E/droid.apps.tip: Not starting debugger since process cannot load the jdwp agent.
2019-06-01 14:05:41.887 12270-12270/? E/tips-smartspace-binder: PSS session is null
2019-06-01 14:06:01.953 12294-12294/? E/.android.diale: Not starting debugger since process cannot load the jdwp agent.
2019-06-01 14:06:02.007 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:06:17.658 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:06:26.866 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:06:26.866 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:06:37.037 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:06:37.044 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:06:37.150 12331-12331/? E/android.youtub: Not starting debugger since process cannot load the jdwp agent.
2019-06-01 14:06:38.527 12331-12360/? E/GEL_DELAYED_EVENT_DEBUG: Failed delayed event dispatch, no dispatchers.
2019-06-01 14:06:40.082 1617-12458/? E/ResolverController: No valid NAT64 prefix (100,<unspecified>/0)
2019-06-01 14:07:10.825 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:07:10.841 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:07:26.874 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:07:26.875 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:07:43.551 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:07:53.566 1869-1975/? E/ClipboardService: Denying clipboard access to com.google.android.as, application is not in focus neither is the IntelligeService for user 0
2019-06-01 14:08:26.881 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:08:26.882 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:09:26.895 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:09:26.895 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:10:26.941 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:10:26.941 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:11:10.114 1869-1887/? E/AppIdleHistory: Error writing app idle file for user 0
2019-06-01 14:11:26.953 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:11:26.954 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2019-06-01 14:11:42.263 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:11:42.270 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:11:42.270 1869-1887/? E/memtrack: Couldn't load memtrack module
2019-06-01 14:12:26.956 1732-1732/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2019-06-01 14:12:26.956 1732-1732/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
вы немного не так сделали. попробуйте этот код. возможно, я тоже где-то ошибся (спешу и убегаю), но направление мысли 100% верное.
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView img1, img2;
private MediaPlayer player; // это сам плеер
int sound1, sound2; // это ваши муз.файлы
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img1 = findViewById(R.id.image1);
img2 = findViewById(R.id.image2);
sound1 = R.raw.sn1;
sound2 = R.raw.sn2;
imageClick();
}
public void imageClick() {
img1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SoundPlay(sound1);
}
}
);
img2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SoundPlay(sound2);
}
}
);
}
public void SoundPlay(int allsounds) {
player = MediaPlayer.create(this, allsounds);
player.start();
}
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Хотите улучшить этот вопрос? Переформулируйте вопрос так, чтобы он был сосредоточен только на одной проблеме
Есть плагин нативный, классы из которого должны войти в итоговый билдНо при включенном proguard'е и минимификации эти классы исключаются из билда