碎片活动无法通过“Intent”打开

时间:2015-05-22 10:30:34

标签: android google-maps android-fragments dictionary fragment

我正在尝试在Markers LatLang Map' by using ListView values上添加. I used 'setOnItemClickListener(),以启动包含Fragment地图的下一个活动。但是当我点击应用关闭的任何ListView项目时。我的代码是

InboxActivity.java

public class InboxActivity extends ActionBarActivity {
String phoneNo;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_inbox);
    Bundle phno=getIntent().getExtras();
    phoneNo=phno.getString("no");
    Toast.makeText(getApplicationContext(), phoneNo, Toast.LENGTH_LONG).show();
    final ListView listView=(ListView)findViewById(R.id.listView1);
    List<String> msgList=getSMS();
    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,msgList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            String str=(String)parent.getItemAtPosition(position);
            Bundle bundle=new Bundle();
            bundle.putString("latlang",str);
            Intent intent1=new Intent(InboxActivity.this,MapActivity.class);
            intent1.putExtras(bundle);
            startActivity(intent1);
        }
    });
}

private List<String> getSMS() {
    List<String>sms=new ArrayList<String>();
    final String SMS_URI_INBOX="content://sms/inbox";
    try {
        Uri uri=Uri.parse(SMS_URI_INBOX);
        String[] projection=new String[]{"_id","address","person","body","date","type"};
        Cursor cursor=getContentResolver().query(uri,projection,"address='"+"+91"+phoneNo+"'",null,null);
        if (cursor.moveToFirst()){
            int index_Address = cursor.getColumnIndex("address");
            int index_Person = cursor.getColumnIndex("person");
            int index_Body = cursor.getColumnIndex("body");
            int index_Date = cursor.getColumnIndex("date");
            int index_Type = cursor.getColumnIndex("type");
            do {
                String strAddress = cursor.getString(index_Address);
                int intPerson = cursor.getInt(index_Person);
                String strBody = cursor.getString(index_Body);
                String longDate = cursor.getString(index_Date);
                int intType = cursor.getInt(index_Type);
                sms.add("\n"+strBody+"\n");
            }while (cursor.moveToNext());
            if (cursor.isClosed()){
                cursor.close();
                cursor=null;
            }
        }
    }catch (SQLiteException e){
        Log.d("SQLiteException",e.getMessage());
    }
    return sms;
}

MapActivity.java

public class MapActivity extends ActionBarActivity {

private GoogleMap mMap;
String locationValues;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (mMap == null) {
        mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment1)).getMap();
        if (mMap != null) {
            setUpMap();
        }
    }
}

private void setUpMap() {
    mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}

activity_inbox.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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.smstrack.InboxActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:text="Location Messages" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="27dp" >
</ListView>

activity_map.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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.smstrack.MapActivity" >

<fragment
    android:id="@+id/fragment1"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true" />

我的LogCat

`05-22 06:35:07.951: E/AndroidRuntime(2514): FATAL EXCEPTION: main
05-22 06:35:07.951: E/AndroidRuntime(2514): Process: com.example.smstrack, PID: 2514
05-22 06:35:07.951: E/AndroidRuntime(2514): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smstrack/com.example.smstrack.MapActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.os.Handler.dispatchMessage(Handler.java:102)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.os.Looper.loop(Looper.java:136)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread.main(ActivityThread.java:5017)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invokeNative(Native Method)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invoke(Method.java:515)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at dalvik.system.NativeStart.main(Native Method)
05-22 06:35:07.951: E/AndroidRuntime(2514): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.Activity.setContentView(Activity.java:1929)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.example.smstrack.MapActivity.onCreate(MapActivity.java:22)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.Activity.performCreate(Activity.java:5231)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-22 06:35:07.951: E/AndroidRuntime(2514):     ... 11 more
05-22 06:35:07.951: E/AndroidRuntime(2514): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 7327000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.common.GooglePlayServicesUtil.zzO(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.internal.zzy.zzai(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.internal.zzy.zzah(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.SupportMapFragment$zzb.zztD(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.dynamic.zza.zza(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
05-22 06:35:07.951: E/AndroidRuntime(2514):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
05-22 06:35:07.951: E/AndroidRuntime(2514):     ... 21 more
`

1 个答案:

答案 0 :(得分:1)

正如你的logcat所说的那样

 Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 7327000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

您应该在google_play_service_version

中添加manifest.xml
 <meta-data
   android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />