我正在关注YouTube教程以创建android应用程序。 在其中一篇教程中,他们讲述了如何使用List活动创建Menu类。使用ListActivity时强制关闭应用程序和ActivityNotFoundException
public class Menu extends ListActivity {
String classes[] = {"Start","example1","example2","example3","example4","example5","example6"};
@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, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourClass = Class.forName("com.example.add." + cheese);
Intent ourIntent = new Intent(Menu.this,ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
并在清单中添加活动。
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:exported="false"
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:exported="false"
android:name="com.example.add.Start"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.add.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我的项目有一个启动类,它增加了一个计数器并显示, 飞溅类定义背景图片,音乐和它的主类。 添加菜单上课之前我的应用程序工作正常,但在我加入这我的应用程序开始强制关闭和logcat的显示,飞溅类的ActivityNotFoundException和错误在第28行
public class Splash extends Activity{
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle Dab) {
// TODO Auto-generated method stub
super.onCreate(Dab);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.nodebeat);
ourSong.start();
Thread timer = new Thread(){
public void run(){ //framework to start a new thread
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStart = new Intent("com.example.add.MENU");
startActivity(openStart);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
所以,请帮助我新的Android应用发展和im袭击在这里。 链接到logcat的日志: - https://docs.google.com/file/d/0BxLaXhL-q50-MHlhUW93SmxNT0U/edit调试日志 https://docs.google.com/file/d/0BxLaXhL-q50-b1pzbVpIcVNQR2s/edit错误日志
感谢。
但在辅导这些方法只是工作得很好,所以我应该怎么去的错误。 –
并非常感谢你,它的工作! –
不客气!至于教程正常工作,总会有错误输入的机会或教程不完全正常工作。总是检查评论 - 通常人们抱怨,如果它不起作用:-) –