2011-08-03 15 views
0

私は小さなブラックベリープロジェクトを開発中です。ファイルをbackberryからWebサービスにアップロードする= JVMエラー104 Uncaught NullPointerException?

  1. ユーザーのクリックを話す:

    は、ここで可能になっているステップです!ボタン。アプリケーション録音音声。 [問題ありません]

  2. ユーザーが終了すると、[停止]をクリックします。ボタン。停止ボタンをクリックすると、音声ボイスはAMRファイルとしてBBに保存されます。その後、ファイルはksoap2経由でWebサービスに送信されます。 Webサービスは応答をファイル名の文字列として返します。問題はWebサービスは何も返しません。エラーが発生しました:JVMエラー104:キャッチされていないNullPointerExceptionコードを正しい場所に配置したのか、ksoap2で何か問題があったのでしょうか?ここ

は、Webサービスのためのコードの下

namespace VoiceServer 
{ 
    /// <summary> 
    /// Converting AMR to WAV 
    /// </summary> 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [System.ComponentModel.ToolboxItem(false)] 

    public class Service1 : System.Web.Services.WebService 
    { 

     public string UploadFile(String receivedByte, String location, String fileName) 
{ 
    String filepath = fileName; 

/*don't worry about receivedByte and location, I will work on them after the problem is  solved :) */ 

    return "Success"+filepath; 
} 

     private void InitializeComponent() 
     { 

     } 
    } 
} 

は、Eclipse上で実行されるコードであり、私は私が正しい場所にWebサービスにファイルを送信するためのコードを置くかはわかりません。

public class MyAudio extends MainScreen { 
private ButtonField _startRecordingButton; 
private ButtonField _stopRecordingButton; 
private HorizontalFieldManager _fieldManagerButtons; 
private VoiceNotesRecorderThread _voiceRecorder; 
private LabelField _myAudioTextField; 
private DateField hourMin; 
private long _initTime; 

public MyAudio() { 
    _startRecordingButton = new ButtonField("Speak!", ButtonField.CONSUME_CLICK); 
    _stopRecordingButton = new ButtonField("Stop!", ButtonField.CONSUME_CLICK); 
    _fieldManagerButtons = new HorizontalFieldManager(); 
    _voiceRecorder = new VoiceNotesRecorderThread(500000,"file:///store/home/user/voicefile.amr",this); 
    _voiceRecorder.start(); 

    myButtonFieldChangeListener buttonFieldChangeListener = new myButtonFieldChangeListener(); 
    _startRecordingButton.setChangeListener(buttonFieldChangeListener);  
    _stopRecordingButton.setChangeListener(buttonFieldChangeListener);  

    _fieldManagerButtons.add(_startRecordingButton); 
    _fieldManagerButtons.add(_stopRecordingButton); 

    _myAudioTextField = new LabelField(" Welcome to VoiceSMS!!!"); 
    add(_fieldManagerButtons); 
    add(_myAudioTextField); 

    SimpleDateFormat sdF = new SimpleDateFormat("ss"); 
    hourMin = new DateField("", 0, sdF); 
    hourMin.setEditable(false); 
    hourMin.select(false); 
    _initTime = System.currentTimeMillis(); 
    add(hourMin); 
} 

public void setAudioTextField(String text) { 
    _myAudioTextField.setText(text); 
} 

public void startTime() { 
    _initTime = System.currentTimeMillis(); 
    hourMin.setDate(0); 
} 

public void updateTime() { 
    hourMin.setDate((System.currentTimeMillis()-_initTime)); 
} 

class myButtonFieldChangeListener implements FieldChangeListener{ 
    public void fieldChanged(Field field, int context) { 
     if(field == _startRecordingButton) { 
      try { 
       _voiceRecorder.startRecording(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     }else if(field == _stopRecordingButton) { 
      _voiceRecorder.stopRecording(); 

      //----------Send AMR to Web Service-------------// 

      Object response = null; 
      String URL = "http://http://localhost:portnumber/Service1.asmx"; 
      String method = "UploadFile"; 
      String NameSpace = "http://tempuri.org/"; 
      FileConnection fc = null; 
      byte [] ary = null; 
      try 
      { 
      fc = (FileConnection)Connector.open("file:///store/home/user/voicefile.amr",Connector.READ_WRITE); 
      int size = (int) fc.fileSize(); 
      //String a = Integer.toString(size); 
      //Dialog.alert(a); 
      ary = new byte[size]; 
      fc.openDataInputStream().read(ary); 
      fc.close(); 
      } 
      catch (IOException e1) 
      { 
      e1.printStackTrace(); 
      } 
      SoapObject client = new SoapObject(NameSpace,method); 
      client.addProperty("receivedByte",new SoapPrimitive(SoapEnvelope.ENC,"base64",Base64.encode(ary))); 
      client.addProperty("location","Test/"); 
      client.addProperty("fileName","file:///store/home/user/voicefile.amr"); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.bodyOut = client; 
      HttpTransport http = new HttpTransport(URL); 

      try 
      { 
      http.call(method,envelope); 
      } 
      catch(InterruptedIOException io) 
      { 
      io.printStackTrace(); 
      } 
      catch (IOException e) 
      { 
      System.err.println(e); 
      } 
      catch (XmlPullParserException e) 
      { 
      System.err.println(e); 

      } 
      catch(OutOfMemoryError e) 
      { 
      System.out.println(e.getMessage()); 
      } 
      catch(Exception e) 
      { 
      e.printStackTrace(); 
      } 

      try 
      { 
      response = envelope.getResponse(); 
      Dialog.alert(response.toString()); 
      } 
      catch (SoapFault e) 
      { 
      System.err.println(e); 
      System.out.println("Soap Fault"); 
      } 
      catch(NullPointerException ne) 
      { 
      System.err.println(ne); 
      } 
      Dialog.alert(response.toString()); 
      //Dialog.alert("Send Success"); 

      //----------End of Upload-to-Web-Service--------// 
     }   
    } 
} 
} 
ファイルは、Webサービス、またはWebサービスに送信されていないファイルを持って、何の応答を生成していない場合、私は知らない

???私はBBプログラミングの本当の初心者です。私が何か悪いことをしてくれたら教えてください。

ありがとうございます!!!

答えて

2

URL変数の値に誤字があります。

"のhttp://" が2回

文字列のURL =型付け "のhttp://のhttp:// localhostを:ポート番号/のService1.asmxを"。

+0

おかげでラファエルに「公共の文字列UploadFile」の上に[WebMethod属性]を追加しました!私はそれを修正しましたが、まだ問題を解決することはできません。 – NandNand

0

Hooray !!!問題が解決しました!ラファエルとして

だけで変更されたURLが提案され、Webサービスのコード

関連する問題