我的基本应用程序有一个小问题。当我试图从列表中的第二个位置("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>发布于 2012-08-30 06:14:22
问题是没有加载IIMODULE类,您是否包含了jar?
请把包装也给我c/p。
发布于 2012-08-30 06:16:26
您正在尝试获取一个不存在的类。
ourClass = Class.forName("com.example.aplikacjatestowa."+ localSelector);
Intent ourIntent = new Intent(Menu.this, ourClass);而不是使用上述代码
Intent ourIntent = new Intent("com.example.aplikacjatestowa."+ localSelector)但是您仍然没有III_Module的操作标记,清单中任何应用程序的操作标记都是空的
https://stackoverflow.com/questions/12187213
复制相似问题