0

I am trying to create a small music app.

I created in such a way that if I click a button it opens a new activity. Every thing is ok but it crashes in the emulator when I click the button to go to new activity.

Can any one help me?

My 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();
    }

}

This is my menu code:

    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();
        }

    }

My 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>

Sorry guys I know how the question should be asked but I am a newbie and please help me and let me know if any other information required to understand my problem.

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>

my LogCat file says this when I run this app.

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

this is my TutorialOne.java file

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);

    }
    }

Guys I m not sure if I posted this in proper manner but I really appreciate your help and also let me know if any other info needed.

akkie4396
  • 101
  • 1
  • 9

2 Answers2

3

Is your activity declared in AndroidManifest.xml ?

If it's not, you have to add this in the manifest within <application> tag :

<activity
    android:name="your.package.name.ClassName"
    android:label="@string/title" >
</activity>
Rogue
  • 751
  • 1
  • 17
  • 36
0

please follow the following 2 points 1. register the activity in manifest using following code android:label="@string/title"> 2. and call the activity in following way startActivity(new Intent(this,TUTORIALONE.class); Hope it will solve your problem

tizbn
  • 1,907
  • 11
  • 16
  • can you please explain this how to do this?? bcoz I think I already did it you can check Menifest file I posted above, if any changes required plz let me knw. – akkie4396 May 19 '14 at 17:19
  • its ok in manifest and what is output when you begin the following code startActivity(new Intent(this,TUTORIALONE.class); it must start next activity or somethings error do post the error if any occured – tizbn May 20 '14 at 02:17
  • it does not show any error when I write this code n save it but it still shows the same error when I launch this app. LogCat is posted above. – akkie4396 May 20 '14 at 08:37
  • have you try this startActivity(new Intent(this,TUTORIALONE.class); hope it will not throw any error – tizbn May 21 '14 at 09:16