我看过类似的帖子,但没有人可以帮助我。我正在制作一对一的语音聊天应用程序。然而它停止了。我还在清单中设置了所有权限。这是清单代码。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bridgecall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.bridgecall.CallActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.bridgecall.sender" >
</activity>
</application>
</manifest>
我可以在这件事上得到任何帮助吗?
这是日志猫:
04-05 17:43:52.427: E/dalvikvm(1415): Could not find class 'javax.sound.sampled.AudioFormat', referenced from method com.bridgecall.CallActivity.getAudioFormat
04-05 17:43:52.427: W/dalvikvm(1415): VFY: unable to resolve new-instance 824 (Ljavax/sound/sampled/AudioFormat;) in Lcom/bridgecall/CallActivity;
04-05 17:43:52.427: D/dalvikvm(1415): VFY: replacing opcode 0x22 at 0x0007
04-05 17:43:52.537: I/dalvikvm(1415): Could not find method javax.sound.sampled.AudioSystem.getMixerInfo, referenced from method com.bridgecall.CallActivity.callStart
04-05 17:43:52.537: W/dalvikvm(1415): VFY: unable to resolve static method 5343: Ljavax/sound/sampled/AudioSystem;.getMixerInfo ()[Ljavax/sound/sampled/Mixer$Info;
04-05 17:43:52.537: D/dalvikvm(1415): VFY: replacing opcode 0x71 at 0x0025
04-05 17:43:52.607: D/dalvikvm(1415): DexOpt: unable to opt direct call 0x14dc at 0x09 in Lcom/bridgecall/CallActivity;.getAudioFormat
04-05 17:43:52.717: D/dalvikvm(1415): DexOpt: unable to opt direct call 0x14e0 at 0x35 in Lcom/bridgecall/CallActivity;.callStart
04-05 17:43:52.717: D/dalvikvm(1415): DexOpt: unable to opt direct call 0x14e0 at 0x61 in Lcom/bridgecall/CallActivity;.callStart
04-05 17:43:53.607: W/dalvikvm(1415): VFY: unable to resolve exception class 831 (Ljavax/sound/sampled/LineUnavailableException;)
04-05 17:43:53.607: W/dalvikvm(1415): VFY: unable to find exception handler at addr 0x10
04-05 17:43:53.617: W/dalvikvm(1415): VFY: rejected Lcom/bridgecall/sender;.<init> ()V
04-05 17:43:53.617: W/dalvikvm(1415): VFY: rejecting opcode 0x0d at 0x0010
04-05 17:43:53.617: W/dalvikvm(1415): VFY: rejected Lcom/bridgecall/sender;.<init> ()V
04-05 17:43:53.637: W/dalvikvm(1415): Verifier rejected class Lcom/bridgecall/sender;
04-05 17:43:53.637: W/dalvikvm(1415): Class init failed in newInstance call (Lcom/bridgecall/sender;)
04-05 17:43:53.637: D/AndroidRuntime(1415): Shutting down VM
04-05 17:43:53.637: W/dalvikvm(1415): threadid=1: thread exiting with uncaught exception (group=0xb3a66ba8)
04-05 17:43:53.677: E/AndroidRuntime(1415): FATAL EXCEPTION: main
04-05 17:43:53.677: E/AndroidRuntime(1415): Process: com.bridgecall, PID: 1415
04-05 17:43:53.677: E/AndroidRuntime(1415): java.lang.VerifyError: com/bridgecall/sender
04-05 17:43:53.677: E/AndroidRuntime(1415): at java.lang.Class.newInstanceImpl(Native Method)
04-05 17:43:53.677: E/AndroidRuntime(1415): at java.lang.Class.newInstance(Class.java:1208)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.os.Handler.dispatchMessage(Handler.java:102)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.os.Looper.loop(Looper.java:136)
04-05 17:43:53.677: E/AndroidRuntime(1415): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-05 17:43:53.677: E/AndroidRuntime(1415): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 17:43:53.677: E/AndroidRuntime(1415): at java.lang.reflect.Method.invoke(Method.java:515)
04-05 17:43:53.677: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-05 17:43:53.677: E/AndroidRuntime(1415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-05 17:43:53.677: E/AndroidRuntime(1415): at dalvik.system.NativeStart.main(Native Method)
04-05 17:43:57.027: I/Process(1415): Sending signal. PID: 1415 SIG: 9
和我的CallActivity类
package com.bridgecall;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class CallActivity extends Activity {
boolean stopCapture = false;
ByteArrayOutputStream byteArrayOutputStream;
AudioFormat audioFormat;
TargetDataLine targetDataLine;
AudioInputStream audioInputStream;
BufferedOutputStream out = null;
BufferedInputStream in = null;
Socket sock = null;
SourceDataLine sourceDataLine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
Intent intent = new Intent(this, sender.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.call, menu);
return true;
}
public void callStart()
{
try {
int port = 6039;
String host= "192.168.1.120";
sock = new Socket(host, port);
out = new BufferedOutputStream(sock.getOutputStream());
in = new BufferedInputStream(sock.getInputStream());
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
TargetDataLine.class, audioFormat);
Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);
targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
Thread captureThread = new CaptureThread();
captureThread.start();
DataLine.Info dataLineInfo1 = new DataLine.Info(
SourceDataLine.class, audioFormat);
sourceDataLine = (SourceDataLine) AudioSystem
.getLine(dataLineInfo1);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
} catch (Exception e) {
}
}
class CaptureThread extends Thread {
byte tempBuffer[] = new byte[1000];
public void run() {
byteArrayOutputStream = new ByteArrayOutputStream();
stopCapture = false;
try {
while (!stopCapture) {
int cnt = targetDataLine.read(tempBuffer, 0,
tempBuffer.length);
out.write(tempBuffer);
if (cnt > 0) {
byteArrayOutputStream.write(tempBuffer, 0, cnt);
}
}
byteArrayOutputStream.close();
} catch (Exception e) {
}
}
}
private AudioFormat getAudioFormat() {
float sampleRate = 8000.0F;
int sampleSizeInBits = 8;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
bigEndian);
}
}
和发件人类:
package com.bridgecall;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
public class sender {
ServerSocket MyService;
Socket clientSocket = null;
BufferedInputStream input;
TargetDataLine targetDataLine;
BufferedOutputStream out;
ByteArrayOutputStream byteArrayOutputStream;
AudioFormat audioFormat;
SourceDataLine sourceDataLine;
byte tempBuffer[] = new byte[1000];
public sender() {
try
{
mysender();
}
catch(LineUnavailableException e)
{
}
}
public void mysender() throws LineUnavailableException {
try {
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info( SourceDataLine.class,audioFormat);
sourceDataLine = (SourceDataLine)
AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
int port= 6039;
MyService = new ServerSocket(port);
clientSocket = MyService.accept();
captureAudio();
input = new BufferedInputStream(clientSocket.getInputStream());
out = new BufferedOutputStream(clientSocket.getOutputStream());
while(input.read(tempBuffer)!=-1){
sourceDataLine.write(tempBuffer,0,1000);
}
} catch (IOException e) {
}
}
private AudioFormat getAudioFormat(){
float sampleRate = 8000.0F;
int sampleSizeInBits = 8;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(
sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
}
private void captureAudio() {
try {
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(
TargetDataLine.class, audioFormat);
Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);
targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
Thread captureThread = new CaptureThread();
captureThread.start();
} catch (Exception e) {
}
}
class CaptureThread extends Thread {
byte tempBuffer[] = new byte[1000];
public void run() {
try {
while (true) {
int cnt = targetDataLine.read(tempBuffer, 0,
tempBuffer.length);
out.write(tempBuffer);
}
} catch (Exception e) {
}
}
}
public static void main(String args[]) {
new sender();
}
}
答案 0 :(得分:0)
您尚未在AndroidManifest中声明sender
活动,这会导致ActivityNotFoundException
。
答案 1 :(得分:0)
未找到javax.sound.sampled.AudioFormat类
包括课程和应用程序将启动