0

I am using intent to call another activity and passing the listview's value to the second activity but getting error on click on the listview selection. Getting

Below is my MainActivity

package com.listview_gps;

public class MainActivity extends ListActivity {

String [] locations = {
    "KFC",
    "McDonalds",
    "A & W",
    "Burger King",
    "Tesco",
    "Home"
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);
    setListAdapter(new ArrayAdapter<String>(this,    android.R.layout.simple_list_item_1, locations));
}

public void onListItemClick(
        ListView parent, View v, int position, long id)
{
    Intent intent = new Intent(MainActivity.this, location_gps.class);
    intent.putExtra("Location", locations[position].toString());
    startActivity(intent);      

}

My Second Activity

Package com.listview_gps;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class location_gps extends Activity{

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

    TextView nameView = (TextView) findViewById(R.id.locationgps);
    nameView.setText(getIntent().getExtras().getString("Location"));
}

}

My Manifest

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.listview_gps.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>
    <activity 
        android:name = ".location_gps"
        android:label="Location GPS" >
        <intent-filter>
            <action android:name = "com.listview_gps" />
            <category android:name = "android.intent.category.DEFAULT" />
            </intent-filter>
        ></activity>
</application>

</manifest>
4

1 に答える 1

0

クラス名は大文字で始まる必要があるため、クラス名 location_gps を Location_gps に変更し、マニフェスト内のすべての場所でも変更が加えられていることを確認してください

于 2013-08-14T08:14:07.353 に答える