我正在解析更新评论的网络服务UpdateLogComment
。我在更新时取得了成功,而我第一次更新评论。当我第二次设置评论时(在edittext中添加一些旧文本)我遇到了问题: -
01-11 16:28:20.900: INFO/System.out(19084): comment is Comment GFFFFGC
01-11 16:28:20.990: WARN/System.err(19084): java.io.FileNotFoundException: http://MY_URL/Webservices/Service.asmx/UpdateLogComment?ScoreId=13172&MachineName=DOTNETSERVER&UserComment=Comment GFFFFGC
01-11 16:28:20.990: WARN/System.err(19084): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
01-11 16:28:20.990: WARN/System.err(19084): at java.net.URL.openStream(URL.java:645)
01-11 16:28:20.990: WARN/System.err(19084): at com.RecordingApp.commentPortion$2.onClick(commentPortion.java:83)
01-11 16:28:21.000: WARN/System.err(19084): at android.view.View.performClick(View.java:2532)
01-11 16:28:21.000: WARN/System.err(19084): at android.view.View$PerformClick.run(View.java:9277)
01-11 16:28:21.000: WARN/System.err(19084): at android.os.Handler.handleCallback(Handler.java:587)
01-11 16:28:21.000: WARN/System.err(19084): at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 16:28:21.000: WARN/System.err(19084): at android.os.Looper.loop(Looper.java:143)
01-11 16:28:21.000: WARN/System.err(19084): at android.app.ActivityThread.main(ActivityThread.java:4196)
01-11 16:28:21.000: WARN/System.err(19084): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 16:28:21.010: WARN/System.err(19084): at java.lang.reflect.Method.invoke(Method.java:507)
01-11 16:28:21.010: WARN/System.err(19084): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-11 16:28:21.010: WARN/System.err(19084): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-11 16:28:21.010: WARN/System.err(19084): at dalvik.system.NativeStart.main(Native Method)
这是我的代码::
package com.RecordingApp;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.Toast;
public class commentPortion extends Activity {
Intent intent_recordingclass;
EditText ED_cmt_txvx;
Button Btn_cmt_ok,
Btn_cmt_cacel;
String str_ScoreId,
str_get_Comment;
Intent Intent_Get_Val_frm_othr;
int int_spnr_choose_item_first_or_sec;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comment);
ED_cmt_txvx = (EditText)findViewById(R.id.cmment_comment_edtx);
Btn_cmt_ok = (Button)findViewById(R.id.cmt_btn_ok);
Btn_cmt_cacel = (Button)findViewById(R.id.cmt_cacel);
Intent_Get_Val_frm_othr = getIntent();
str_ScoreId = Intent_Get_Val_frm_othr.getStringExtra("scoreID");
str_get_Comment = Intent_Get_Val_frm_othr.getStringExtra("usercomment");
int_spnr_choose_item_first_or_sec= Intent_Get_Val_frm_othr.getIntExtra("spnritem",0);
ED_cmt_txvx.setText(str_get_Comment);
Btn_cmt_cacel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent itemsele = new Intent(commentPortion.this,LogList.class);
itemsele.putExtra("spnritem", int_spnr_choose_item_first_or_sec);
itemsele.putExtra("machineName", Recording.str_Machinename);
itemsele.putExtra("value", Recording.str_getValue);
startActivity(itemsele);
finish();
}});
Btn_cmt_ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
String Comment = ED_cmt_txvx.getText().toString();
System.out.println("comment is "+Comment);
if(Comment.equalsIgnoreCase(""))
{
Toast.makeText(getBaseContext(), "Comment is Blank", Toast.LENGTH_LONG).show();
}
else
{
try
{
String sourceUrl1 = "http://My_url/Webservices/Service.asmx/UpdateLogComment?ScoreId="+str_ScoreId+"&MachineName="+Recording.str_Machinename+"&UserComment="+Comment+"";
URL sourceUrl = new URL(sourceUrl1);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
commentHandler dataHandler = new commentHandler();
xr.setContentHandler(dataHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
commentDataset dataset = dataHandler.getParsedcomment_DataSet();
String flag_sucess_send_commnt = dataset.getboolean1();
AlertDialog.Builder alertbox = new AlertDialog.Builder(commentPortion.this);
System.out.println("flag_sucess_send_commnt"+flag_sucess_send_commnt);
if(flag_sucess_send_commnt.equalsIgnoreCase("true"))
{
alertbox.setTitle("Message");
alertbox.setMessage("Comment added Sucessfully");
alertbox.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent itemsele = new Intent(commentPortion.this,LogList.class);
itemsele.putExtra("spnritem", int_spnr_choose_item_first_or_sec);
itemsele.putExtra("machineName", Recording.str_Machinename);
itemsele.putExtra("value", Recording.str_getValue);
startActivity(itemsele);
finish();
}
});
alertbox.show();
}
else
{
Toast.makeText(getBaseContext(), "Comment not Update,Please Try Again", Toast.LENGTH_LONG).show();
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
}
答案 0 :(得分:0)
关于在两个单词之间输入评论空间的问题。使URL编码并再次尝试。我在adressbar中取得了成功。但是当我复制它并发现%20是如此严格以至于URL必须被编码并且我得到了解决方案。