안녕하세요
서버에 apmsetup을 설치해서 데이터베이스에 값을 넣으려고 하는데
logcat에 Protocol not found 에러가 뜨는데 생성된 주소를 익스플로러로 실행하면
원하는 기능이 잘 실행되는데 안드로이드에서 실행하려고 하면 안되네요
package com.example.sirwoongke.dbtest;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity
{
private final String SERVER_ADDRESS = "183.101.9.182";
EditText edtName;
EditText edtPrice;
Button btnInsert;
Button btnSearch;
ListView list;
ArrayList<String> data;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtName = (EditText)findViewById(R.id.editText1);
edtPrice = (EditText)findViewById(R.id.editText2);
btnInsert = (Button)findViewById(R.id.button1);
btnSearch = (Button)findViewById(R.id.button2);
list = (ListView)findViewById(R.id.listView1);
data = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
list.setAdapter(adapter);
btnInsert.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(edtName.getText().toString().equals("") || edtPrice.getText().toString().equals("") )
{
Toast.makeText(getApplicationContext(), "이름이나 가격을 입력하세요", Toast.LENGTH_LONG).show();
return;
}
runOnUiThread(new Runnable()
{
public void run()
{
String name = edtName.getText().toString();
String price = edtPrice.getText().toString();
try
{
String urlString = SERVER_ADDRESS + "/insert.php?" + "name=";
urlString += URLEncoder.encode(name, "UTF-8");
urlString += "&price=";
urlString += URLEncoder.encode(price, "UTF-8");
URL url = new URL( urlString ); //오류가 나는 부분
Toast.makeText(getApplicationContext(),"URL", Toast.LENGTH_LONG).show();
url.openStream();
String result = getXmlData("insertresult.xml", "result");
Toast.makeText(getApplicationContext(),"2", Toast.LENGTH_LONG).show();
if(result.equals("1"))
{
Toast.makeText(getApplicationContext(), "DB Insert 성공", Toast.LENGTH_LONG).show();
edtName.setText("");
edtPrice.setText("");
}
else
{
Toast.makeText(getApplicationContext(), "DB Insert 실패", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
Log.e("Error", e.getMessage());
}
}
});
}
});
private String getXmlData(String filename, String str) {
String rss = SERVER_ADDRESS + "/";
String ret = "";
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
URL server = new URL(rss + filename);
InputStream is = server.openStream();
xpp.setInput(is, "UTF-8");
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equals(str)) {
ret = xpp.nextText();
}
}
eventType = xpp.next();
}
} catch (Exception e) {
Log.e("Error", e.getMessage());
}
return ret;
}
답변 부탁드려요