【发布时间】:2018-02-04 15:52:52
【问题描述】:
如何编写 Android 应用程序来接收来自 Yamaha YDP-113 电子钢琴的 MIDI 事件?
当我强制它时,我得到一个运行时错误:
FATAL EXCEPTION: main
Process: com.example.android.miditest, PID: 19022
java.lang.NoClassDefFoundError: android.media.midi.MidiManager
hasSystemFeature() 方法返回 false:
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) {
// do MIDI stuff
Log.d("MainActivity-onCreate", "has MIDI feature");
TextView info = (TextView) findViewById(R.id.info_text_view);
info.setText("MIDI found!");
MidiManager m = (MidiManager) getSystemService(Context.MIDI_SERVICE);
}
else {
Log.d("MainActivity-onCreate", "cannot find MIDI feature");
TextView info = (TextView) findViewById(R.id.info_text_view);
info.setText("Sorry, no MIDI");
}
这是我的清单:
<uses-feature android:name="android.software.midi" android:required="true"/>
<uses-feature android:name="android.hardware.usb.host"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我相信这一定是可能的,因为我安装了 AppsTransport 的“USB Midi Keyboard”,它在 Google Play Store 上有 100,000 次下载。当我在 Yamaha YDP-113 上弹奏音符时,该应用程序会显示我按下的钢琴键盘琴键,甚至发出声音!
其他开发人员正在使用什么来开发与我的键盘、MIDI-USB 电缆和三星平板电脑配合使用的应用程序?我需要在手机上安装什么吗?或者我需要告诉 gradle 一些包或下载?
【问题讨论】:
-
您是否在
AndroidManifest.xml中声明了该功能? -
是的。似乎 Android Studio 3.0 正在编译我的代码,但出现运行时错误:java.lang.NoClassDefFoundError: android.media.midi.MidiManager