我正在尝试创建一个小型音乐应用。
我创建的方式是,如果单击按钮,则会打开一个新活动。一切都还可以,但是当我点击按钮进入新活动时,它会在模拟器中崩溃。
任何人都可以帮助我吗?
我的MainActivity.java:
package com.example.musicapp;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
MediaPlayer logoMusic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
logoMusic = MediaPlayer.create(MainActivity.this, R.raw.splash_sound);
logoMusic.start();
Thread logoTimer = new Thread(){
public void run(){
try{
sleep(5000);
Intent menuIntent = new Intent("com.example.musicapp.MENU");
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
logoMusic.release();
}
}
这是我的菜单代码:
package com.example.musicapp;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Setting up click sound of buttons
final MediaPlayer buttonSound = MediaPlayer.create(menu.this, R.raw.btn_sound);
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.musicapp.TUTORIALONE"));
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
我的activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg1"
android:orientation="vertical"
tools:context="com.example.musicapp.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="@string/welcome"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/tutorial1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="@string/btn1"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@+id/tutorial2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="@string/btn2"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
对不起家伙我知道应该如何问这个问题,但我是新手,请帮助我,如果有任何其他信息需要了解我的问题,请告诉我。
here is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.musicapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.musicapp.MainActivity"
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:name=".menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.musicapp.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialOne"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.musicapp.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
当我运行此应用程序时,我的LogCat文件说明了这一点。
05-19 09:28:03.966: I/dalvikvm(280): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-19 09:28:03.966: W/dalvikvm(280): VFY: unable to resolve virtual method 318: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-19 09:28:03.966: D/dalvikvm(280): VFY: replacing opcode 0x6e at 0x008b
05-19 09:28:03.966: I/dalvikvm(280): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-19 09:28:03.976: W/dalvikvm(280): VFY: unable to resolve virtual method 314: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-19 09:28:03.976: D/dalvikvm(280): VFY: replacing opcode 0x6e at 0x0099
05-19 09:28:03.996: D/dalvikvm(280): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-19 09:28:04.006: D/dalvikvm(280): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-19 09:28:12.876: D/AndroidRuntime(280): Shutting down VM
05-19 09:28:12.876: W/dalvikvm(280): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-19 09:28:12.896: E/AndroidRuntime(280): FATAL EXCEPTION: main
05-19 09:28:12.896: E/AndroidRuntime(280): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.musicapp/com.example.musicapp.TutorialOne}: java.lang.ClassNotFoundException: com.example.musicapp.TutorialOne in loader dalvik.system.PathClassLoader[/data/app/com.example.musicapp-1.apk]
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.os.Looper.loop(Looper.java:123)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-19 09:28:12.896: E/AndroidRuntime(280): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 09:28:12.896: E/AndroidRuntime(280): at java.lang.reflect.Method.invoke(Method.java:521)
05-19 09:28:12.896: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-19 09:28:12.896: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-19 09:28:12.896: E/AndroidRuntime(280): at dalvik.system.NativeStart.main(Native Method)
05-19 09:28:12.896: E/AndroidRuntime(280): Caused by: java.lang.ClassNotFoundException: com.example.musicapp.TutorialOne in loader dalvik.system.PathClassLoader[/data/app/com.example.musicapp-1.apk]
05-19 09:28:12.896: E/AndroidRuntime(280): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-19 09:28:12.896: E/AndroidRuntime(280): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-19 09:28:12.896: E/AndroidRuntime(280): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-19 09:28:12.896: E/AndroidRuntime(280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-19 09:28:12.896: E/AndroidRuntime(280): ... 11 more
05-19 09:28:16.186: I/Process(280): Sending signal. PID: 280 SIG: 9
这是我的TutorialOne.java文件
package com.example.musicapp;
import android.app.Activity;
import android.os.Bundle;
public class TurorialOne extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
}
}
伙计我不确定我是否以适当的方式发布此内容,但我非常感谢您的帮助,如果需要任何其他信息,也请告诉我。
答案 0 :(得分:3)
您的活动是否在AndroidManifest.xml中声明?
如果不是,则必须在<application>
标记内的清单中添加:
<activity
android:name="your.package.name.ClassName"
android:label="@string/title" >
</activity>
答案 1 :(得分:0)
请遵循以下2点 1.使用以下代码在清单中注册活动 机器人:标签=&#34; @串/标题&#34;&GT; 2.并按以下方式调用活动 startActivity(new Intent(this,TUTORIALONE.class); 希望它能解决你的问题