我试图将我的android项目连接到php上的数据库,我的代码中没有错误,但当我试图在手机上运行我的应用程序时,它不起作用
public class Historical_Sites extends ListActivity{
private ProgressDialog pDialog;
Json_Parsing jParser = new Json_Parsing();
ArrayList<HashMap<String, String>> SitesList;
private static String url_all_Sites = "http://tourin.esy.es/php/historical.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_POSTS = "posts";
private static final String TAG_SITE_NO="Site_NO";
private static final String TAG_SITE_NAME = "Site_Name";
JSONArray Sites = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.historical_sites);
SitesList = new ArrayList<HashMap<String, String>>();
new LoadAllProducts().execute();
ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String sitname = ((TextView) view.findViewById(R.id.sitenam)).getText()
.toString();
Intent in = new Intent(getApplicationContext(),
Check.class);
in.putExtra(TAG_SITE_NAME, sitname);
startActivityForResult(in, 100);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
class LoadAllProducts extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Historical_Sites.this);
pDialog.setMessage("Loading Historical Sites. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_Sites, "GET", params);
Log.d("All Sites: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Sites = json.getJSONArray(TAG_POSTS);
for (int i = 0; i < Sites.length(); i++) {
JSONObject c = Sites.getJSONObject(i);
String sitno= c.getString(TAG_SITE_NO);
String Sitenam = c.getString(TAG_SITE_NAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_SITE_NO, sitno);
map.put(TAG_SITE_NAME, Sitenam);
SitesList.add(map);
}
} else {
Intent i = new Intent(getApplicationContext(),
Chat.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
Historical_Sites.this, SitesList,
R.layout.historical_sites_rows, new String[] {TAG_SITE_NAME},
new int[] { R.id.sitenam });
setListAdapter(adapter);
}
});
}
}
}
这就是Json_解析
public class Json_Parsing {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public Json_Parsing() { }
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
try {
if(method == "POST"){
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent();
}else if(method == "GET"){
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
public JSONObject getJSONFromUrl(String url) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
/*
*
*
*
*
*
* */
}
我知道,这是我在日志中的错误
e/ViewRootImpl: sendUserAction事件()mView==null
protected void onPostExecute(String file_url) {
pDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
Historical_Sites.this, SitesList,
R.layout.historical_sites_rows, new String[] {TAG_SITE_NAME},
new int[] { R.id.sitenam });
setListAdapter(adapter);
}
我一直在努力让它工作,我想我可以使用一些帮助。我正在做一个Java项目,其中pom.xml有一堆依赖项,其中一些依赖项本身间接依赖于这个jar:如下: 我在pom中需要这个特殊的jar,因为我想使用jax rs api中的新特性:。问题是,当我构建项目时,会出现以下错误: 我试图通过排除来自通过检查依赖关系树包含它的依赖关系。 现在该项目构建良好,但当我尝试运行它时,我得到了这个错误: 似乎需要球
下面是我的Gridle文件,我尝试了stackoverflow other的问题answare中所有可能的解决方案,但仍然显示相同的结果。 错误: 错误:(3)错误检索项目的父:没有找到与给定名称'android: Text外观匹配的资源。材料。小部件。按钮。无国界。有色'。 网格: 这里是使用XML的地方: 将minsdkversion更改为11时出现其他一些错误 错误:任务“:app:proc
问题内容: 我一直在努力使它起作用,我认为我可以使用一些帮助。我正在一个Java项目中,其中pom.xml具有一堆依赖关系,其中一些依赖关系本身间接依赖于此jar : 我需要在pom中使用这个特定的jar,因为我想使用jax-rs api:中的新功能 。问题是在构建项目时出现此错误: 我试图通过排除依赖项来解决此问题,这是通过检查依赖关系树来实现的。 现在项目构建良好,但是当我尝试运行它时,出现此
请看上图。 我该如何解决这个错误? 我的 Windows 电脑有 4 GB 内存,而我的 C 盘中只有 6GB 的可用空间。
D:\gatsby站点 盖茨比起动器-default@0.1.0开发D:\gatsby站点 盖茨比发展 错误 加载插件“gatsby plugin sharp”时出现问题。也许你需要安装它的软件包?使用--verbose查看实际错误。 错误#10226 CONFIG 找不到在“D:\gatsby site\gatsby config.js”中声明的“gatsby plugin sharp”插件。
当我想运行react-native run-android命令时,我会看到 运行jetifier将库迁移到AndroidX的信息。您可以使用“--no-jetifier”标志禁用它。Jetifier找到了998个要转发的文件。使用12名工作人员...信息JS服务器已在运行。安装应用程序得信息... 失败:生成失败,出现异常。 > 其中:构建文件“C:\tmpprojets\beetv-app\no