我试图用以下代码建立本地连接,但由于错误而逐渐弹出。
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetJsonArray obj = new GetJsonArray();
obj.readJson(this);
}
}
GetJsonArray.java
public class GetJsonArray
{
private String SERVER_URL="http://myIPAddress:portNumber/database_name/table_name.jsp";
private Context context;
public void readJson(final Context context)
{
this.context=context;
Toast.makeText(context,"Inside JSON Array class",Toast.LENGTH_LONG).show();
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest stringRequest = new StringRequest(Request.Method.GET, SERVER_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response)
{
if(response.trim().equals("success"))
{
Toast.makeText(context,"Data recieved from server",Toast.LENGTH_LONG).show();
//Log.e("Success",response);
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(context,"Data not recieved from server",Toast.LENGTH_LONG).show();
//Log.e("Error",error.getLocalizedMessage());
}
}){};
queue.add(stringRequest);
}
}
错误 E / LB:无法打开文件:没有这样的文件或目录