从Menu activity(菜单活动)调用GPS活动



我的基本应用程序有一个小问题。当我试图从列表("IIMODULE")开始第二个位置时,我的手机上没有任何反应。这是LogCat:的日志

System.err(3416): java.lang.ClassNotFoundException: com.example.aplikacjatestowa.IIMODULE

我对这个错误几乎没有研究,但我没有发现任何具体的情况。有人能看出我的错误吗?有什么想法吗?

菜单类:

public class Menu extends ListActivity {
String[] mainMenuStrings = { "MAINACTIVITY", "IIMODULE", "III_Module",
        "empty" };
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this,
            android.R.layout.simple_list_item_1, mainMenuStrings));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String localSelector = mainMenuStrings[position];
    Class ourClass;
    try {
        ourClass = Class.forName("com.example.aplikacjatestowa."
                + localSelector);
        Intent ourIntent = new Intent(Menu.this, ourClass);
        startActivity(ourIntent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

}

我称GPS的新活动为:

 public class GpsModule extends Activity {
    public static Context cont;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps);
        cont = getApplicationContext();
        LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        LocationListener locListener = new MyLocationListener();
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                locListener);
    }
}

这是AndroidManifest:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.aplikacjatestowa"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Menu"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="com.example.aplikacjatestowa.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
           android:name=".MainActivity"
           android:label="@string/title_activity_main" >
            <intent-filter>
               <action android:name="com.example.aplikacjatestowa.MAINACTIVITY" />
               <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
           android:name=".GpsModule"
           android:label="@string/title_activity_main" >
            <intent-filter>
               <action android:name="com.example.aplikacjatestowa.IIMODULE" />
               <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

问题是IIMODULE类没有加载,你包括jar了吗?

请把包裹也寄给我。

您正在尝试获取一个不存在的类。

 ourClass = Class.forName("com.example.aplikacjatestowa."+ localSelector);
 Intent ourIntent = new Intent(Menu.this, ourClass);

使用代替上述代码

Intent ourIntent = new Intent("com.example.aplikacjatestowa."+ localSelector)

但是您仍然没有III_Module的操作标签,并且清单中的任何应用程序都为空

最新更新