1) implement web service in netbeans with json which fetch data from MySQL database
2) create rest client in android to call web service
Edited code
my manifest file
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
jsonParse.java
package android.project.srt.demojson;
public class JsonParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JsonParser() {
}
public String getJSONFromUrl(String url) {
// Making HTTP request
try {
HttpGet get = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream inputStream=entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream),8 * 1024);
String line=null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
} catch (UnsupportedEncodingException e) {
Log.e("unsupported ","encoding exception" +e.getMessage());
e.printStackTrace();
} catch (ClientProtocolException e) {
Log.e("clientprotocolexception ","" + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.e("io","Exception " + e.getMessage());
e.printStackTrace();
}
return sb.toString();
}
}
MainActivity.java
public class MainActivity extends ActionBarActivity {
private static String url = "http://192.168.1.31:8084/adminWebservice/mywebservice/SelectRestroTypes";
String categoryname;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textView1);
//new JSONParse().execute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
tv1.setText("Getting Values Pls wait..");
JsonParser jParser = new JsonParser();
// Getting JSON from URL
// JSONObject json = jParser.getJSONFromUrl(url);
String jsonString=jParser.getJSONFromUrl(url);
tv1.setText(jsonString);
}
}
logcat shows this only error :
03-24 19:11:20.914 30629-30629/android.project.srt.demojson E/ViewRootImpl﹕ sendUserActionEvent() mView == null
any suggestions regarding creating json client in android are welcome
thanks in advance for help