Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Nanette Keir
Nanette Keir
17,666 Points

Crystal Ball App for Android/AndroidManifest.xml

Hello,

I have run and tested my Crystal Ball App (on Emulator and my Android Phone) and have had no problems until this point. When I went into the AndroidManifest.xml to change the label to Crystal Ball and delete the Label name under Main Activity area in application I started getting this message:

Class referenced in the manifest, com.example.crystalball.MainActivity, was not found in the project or the libraries AndroidManifest.xml /Crystal Ball line 14 Android Lint Problem

It says in that there are 19 items but I have no errors anywhere else except here in the AndroidManifest.xml.

I know it's probably something I did but not too sure what I have done. Any help would be greatly appreciated!

14 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Everything looks good. Can you try cleaning your project and rebuilding (Project > Clean...)? I show how to change the package name to com.teamtreehouse.crystalball in the last stage of the project, but that shouldn't cause any problems as long as your stuff is consistent.

This seems to be a case where something in your project is cached/corrupted. After cleaning and rebuilding, you might want to even restart Eclipse. And do feel free to email us your code.

Also, you did paste all the manifest in, but it wasn't showing up because of how Markdown (which we use to format these posts) handles code. You need to either indent all your code four spaces, or surround it with three backticks, like this:

```

Code code code!

```

And you can specify a language after the backticks if you want, like this:

```java

String test = "this is some text!";

```

```xml

<manifest>

</manifest>

```

Thanks Ben :) Cleaning the project did the trick for me !

habib kazemi
habib kazemi
2,041 Points

I did the project>clean fixed.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

It looks like there's a problem with your manifest where MainActivity is declared. Can you paste your manifest code in here and/or zip up your project and email it to help@teamtreehouse.com?

Nanette Keir
Nanette Keir
17,666 Points

Thanks so much for you help Ben! I hope this is what you need to tell me where I went wrong.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.crystalball" android:versionCode="1" android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="Crystal Ball"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Nanette Keir
Nanette Keir
17,666 Points

I forgot to mention when I hover over the error message in the manifest and get more info it states this:

Class referenced in the manifest, com.example.crystalball.MainActivity, was not found in the project or the libraries.

Issue Explanation: If a class is referenced in the manifest, it must also exist in the project (or in one of the libraries included by the project. This check helps uncover typos in registration names, or attempts to rename or move classes without updating the manifest file properly.

It sounds like I might have mistyped something from the very start but it did not manifest itself until this point? Sorry for all the trouble, very much a newbie at coding!

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

The first thing I would try is adding the whole package name in your <activity> element, like this:

<activity
        android:name="com.example.crystalball.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

Make sure that the package name matches exactly what you have as the first line in your MainActivity.java file.

Manifest errors can be tricky because they're usually the result of some other weird change, and it's not like you can debug them to see exactly where it's breaking. You have to depend on helpful error messages, which is never a sure thing!

Let me know if that helps or not and if not, then you can email your whole project to help@teamtreehouse.com.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Oh, and I was hoping you could post the rest of your manifest file, too, because it includes the package name. Here's what mine looks like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.teamtreehouse.crystal.ball"
    android:versionCode="1"
    android:versionName="1.0" >
Nanette Keir
Nanette Keir
17,666 Points

Here's the whole manifest, sorry I thought I sent the whole item:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.crystalball"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="Crystal Ball"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <activity
        android:name="com.example.crystalball.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
    </application>

</manifest>

Here also is the MainActivity. java:

package com.example.crystalball;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.crystalball.ShakeDetector.OnShakeListener;

public class MainActivity extends Activity {

    public static final String TAG = MainActivity.class.getSimpleName();

    private CrystalBall mCrystalBall = new CrystalBall();
    private TextView mAnswerLabel;
    private ImageView mCrystalBallImage;
    private SensorManager mSensorManager;
    private Sensor mAccelerometer;
    private ShakeDetector mShakeDetector;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Assign the Views from the layout file
        mAnswerLabel = (TextView) findViewById(R.id.textView1);
        mCrystalBallImage = (ImageView) findViewById(R.id.imageView1);
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mShakeDetector = new ShakeDetector(new OnShakeListener(){

            @Override
            public void onShake() {
                handleNewAnswer();

            }
        });


        //Toast.makeText(this, "Yay! Our Activity was created!",Toast.LENGTH_LONG).show();
       Log.d(TAG, "We're logging from the onCreate() method!");

    }
    @Override
    public void onResume(){
        super.onResume();

        mSensorManager.registerListener(mShakeDetector, mAccelerometer, 
            SensorManager.SENSOR_DELAY_UI);


    }
    @Override
    public void onPause(){
        super.onPause();
        mSensorManager.unregisterListener(mShakeDetector);

    }

    private void animateCrystallBall(){

        mCrystalBallImage.setImageResource(R.drawable.ball_animation);
        AnimationDrawable ballAnimation = (AnimationDrawable) mCrystalBallImage.getDrawable();
        if (ballAnimation.isRunning()){
            ballAnimation.stop();

        }
        ballAnimation.start();

    }

    private void animateAnswer() {
        AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
        fadeInAnimation.setDuration(1500);
        fadeInAnimation.setFillAfter(true);
        mAnswerLabel.setAnimation(fadeInAnimation);
    }

    private void playSound() {
        MediaPlayer player = MediaPlayer.create(this, R.raw.crystal_ball);
        player.start();
        player.setOnCompletionListener(new OnCompletionListener() {


            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.release();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    private void handleNewAnswer() {
        String answer = mCrystalBall.getAnAnswer();


        // Update the label with our dynamic answerp
        mAnswerLabel.setText(answer);

        animateCrystallBall();
        animateAnswer();
        playSound();
    }

}

Every where in my code (CrystalBall.java, MainActivity.java and ShakeDetector.java it states:

package com.example.crystalball;

My guess is from the very start I didn't put com.teamtreehouse.crystal.ball. Doh! I will also send my zipped file if I can.

Nanette Keir
Nanette Keir
17,666 Points

Hooray!! That Project>Clean fixed it!! Thanks again for all your help and thanks again for the fun classes!!

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Woo hoo! Glad it worked. It might be worth adding a troubleshooting video about doing things like that to help people who stumble across this in the future.

I just ran into the same problem and the Project > Clean fixed it. Thanks for the help!

Had same issue. Project > Clean fixed it. Could always get it to repeat by manually editing the AndroidManifest.xml (instead of using the 'Application' tab) within Eclipse. Project > Clean has always resolved. it. Thanks

I ran into the same problem and Project > Clean fixed it too. Thanks!

habib kazemi
habib kazemi
2,041 Points

I have an error in this part of manifest:

<?xml version="1.0" encoding="utf-8"?>

Hi Habib. I read that you tried Project > Clean. I suppose, maybe, it either did not work for you or that it has happened again. In my experience when I edited the manifest directly it would cause issues. Or whenever an issue referencing the manifest occurs, Project > Clean would resolve for me. (I may have even used the command more than once)