所以我是新來的,並在android程序上工作,以處理活動和東西無論如何,即時通訊有沒有發現異常類的問題。所以當我運行應用程序時,我得到了我所有活動的列表,當我選擇他們中的任何一個都沒有工作時,我得出結論它的.forName行,即時通訊使用它正確.forName(「包」 + className),其中所有類都位於我的包和拼寫中是正確的。但沒有找到! 這裏是我的代碼全部所有測試數組中的項目是我的活動應用程序活動崩潰
public class MainActivity extends ListActivity {
String tests [] = {"LifeCycleTest","SingleTouchTest","MultiTouchTest","KeyTest","AccelerometerTest","AssetsTest",
"ExternalStorageTest","SoundPoolTest","MediaPlayerTest","FullScreenTest","RenderViewTest","ShapeTest","BitmapTest",
"FontTest","SurfaceViewTest"};
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,tests));
}
@Override
protected void onListItemClick(ListView list, View view, int position, long id){
super.onListItemClick(list,view,position, id);
String testName = tests[position];
// my problem
try {
Class clazz = Class
.forName("test.com." + testName);
Intent intent = new Intent(this, clazz);
startActivity(intent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
}
所以我說的.forName(「test.com。」 +級),現在它只是崩潰,這裏的生命週期類長什麼樣就像我試圖選擇它一樣。 iv完全沒有想法。
public class LifeCycleTest extends Activity{
StringBuilder builder = new StringBuilder();
TextView textView;
private void log(String text){
Log.d("LifeCycleTest",text);
builder.append(text);
builder.append('\n');
textView.setText(builder.toString());
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText(builder.toString());
setContentView(textView);
log("created");
}
@Override
protected void onResume(){
super.onResume();
log("resumed");
}
@Override
protected void onPause(){
super.onPause();
log("Paused");
if(isFinishing()){
log("finishing");
}
}
}
這是我的清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fox.com"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<application android:label="@string/app_name"
android:icon="@drawable/mrnom"
android:debuggable="true">
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation">
<activity android:label="Life Cycle Test"
android:name=".LifeCycleTest"
android:configChanges="keyboard|keyboardHidden|orientation"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="16"/>
</manifest>
看起來我好像有一個點遺漏。試試這個forName(「test.com。」+ testName); –