我正在尝试从在线服务器读取一些数据,并在ListView中动态添加它们。不幸的是它崩溃了android.content.ActivityNotFoundException
但我的活动在清单中声明,所以我不明白问题是什么。
这是我的java文件:
public class Marker extends Activity {
// Retrieve COMMENTS from database
String myJSON;
private static final String TAG_RESULTS="result";
private static final String TAG_ID = "id";
private static final String TAG_POI = "poi";
private static final String TAG_USERNAME ="username";
private static final String TAG_COMMENT = "comment";
JSONArray comments = null;
// ListView
private ListView lv;
private ArrayList<String> strArr;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_marker);
// Retrieve COMMENTS from database
getData();
}
// Retrieve COMMENTS from database
protected void showList(){
try {
lv = (ListView) findViewById(R.id.list);
strArr = new ArrayList<String>();
JSONObject jsonObj = new JSONObject(myJSON);
comments = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<comments.length();i++){
JSONObject c = comments.getJSONObject(i);
Integer id = c.getInt(TAG_ID);
String name = c.getString(TAG_POI);
String username = c.getString(TAG_USERNAME);
String comment = c.getString(TAG_COMMENT);
strArr.add("Row:" + comment);
}
adapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, strArr);
lv.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getData(){
class GetDataJSON extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://xxxx/comments_out.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
@Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_marker_page, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.diana.track.MarkerPage">
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
我的Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.diana.track" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".myprofile"
android:label="@string/title_activity_myprofile" >
</activity>
<activity
android:name=".Track"
android:label="@string/title_activity_track" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".map"
android:label="@string/title_activity_map" >
</activity>
<activity
android:name=".NotificationView"
android:label="@string/title_activity_notification_view" >
</activity>
<activity
android:name=".ProximityActivity"
android:label="@string/title_activity_proximity" >
</activity>
<activity
android:name=".AddPoi"
android:label="@string/title_activity_add_poi" >
</activity>
<activity
android:name=".ShortPath"
android:label="@string/title_activity_short_path" >
</activity>
<activity
android:name=".profile"
android:label="@string/title_activity_profile" >
</activity>
<activity
android:name=".Marker"
android:label="@string/title_activity_marker" >
</activity>
</application>
</manifest>
和我的logcat
07-16 18:34:27.659 8628-9083/com.example.diana.track D/-heap﹕ GC_FOR_ALLOC freed 3574K, 38% free 7122K/11376K, paused 57ms, total 65ms
07-16 18:34:28.059 8628-8628/com.example.diana.track I/Choreographer﹕ Skipped 37 frames! The application may be doing too much work on its main thread.
07-16 18:34:28.440 8628-9075/com.example.diana.track D/-heap﹕ GC_FOR_ALLOC freed 1605K, 35% free 7482K/11376K, paused 34ms, total 34ms
07-16 18:34:29.050 8628-9083/com.example.diana.track D/-heap﹕ GC_FOR_ALLOC freed 501K, 33% free 7648K/11376K, paused 33ms, total 35ms
07-16 18:34:29.050 8628-9083/com.example.diana.track I/dalvikvm-heap﹕ Grow heap (frag case) to 11.080MB for 1048592-byte allocation
07-16 18:34:30.041 8628-8628/com.example.diana.track D/AndroidRuntime﹕ Shutting down VM
07-16 18:34:30.041 8628-8628/com.example.diana.track W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415478b0)
07-16 18:34:30.061 8628-8628/com.example.diana.track E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.diana.track/com.google.android.gms.maps.model.Marker}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at android.app.Activity.startActivity(Activity.java:3587)
at android.app.Activity.startActivity(Activity.java:3555)
at com.example.diana.track.map.onMarkerClick(map.java:765)
at com.google.android.gms.maps.GoogleMap$10.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzn$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:347)
at com.google.android.gms.maps.internal.bd.a(SourceFile:84)
at com.google.maps.api.android.lib6.d.as.b(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.c.e.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.av.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.be.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.bd.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.bt.d(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.n.ak.onSingleTapConfirmed(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.h.g.onSingleTapConfirmed(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.h.i.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
知道可能是什么问题吗?