所以我是新来的,并在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); –