2012-08-29 88 views
0

我的基本应用程序有一个小问题。当我尝试从列表(“IIMODULE”)开始第二个位置时,我的手机没有任何反应。这里的日志来自LogCat:从菜单活动调用GPS活动

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

我对这个错误的研究很少,但是我没有发现任何特定的情况。任何人都可以看到我的错误?有任何想法吗?

Menu类:

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> 
+1

任何应用程序你有一个名为''IIMODULE''类在你的应用程序? – harism

+0

omg ...我没有解释这种微不足道的错误 –

回答

1

的问题是, IIMO DULE课没有加载,你有没有加入罐子?

pls c/p的包也。

1

你正试图得到一个不存在的类。

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

而不是上面的代码使用

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

但是你还是不要有III_Module行动标签和空在清单