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 Build a Simple Android App Improving Our Code Using the New Colors

Dariusz G贸rski
Dariusz G贸rski
5,515 Points

App cannot run even without errors in code

I have error like that when I try to run my app:

07-13 16:38:08.341 7268-7268/com.example.darek.funfacts E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.darek.funfacts, PID: 7268 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.darek.funfacts/com.example.darek.funfacts.FunFactsActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.darek.funfacts.FunFactsActivity" on path: DexPathList[[zip file "/data/app/com.example.darek.funfacts-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.darek.funfacts-2/lib/x86, /vendor/lib, /system/lib]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102)

I am stucked and have no idea what else can I check.

Dariusz G贸rski
Dariusz G贸rski
5,515 Points

Here are my files: package com.example.darek.funfacts;

import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView;

import java.util.Random;

public class FunFactsActivity extends AppCompatActivity {



//Declare our View variables

private TextView mFactTextView;
private Button mShowFactButton;
private RelativeLayout mRelativeLayout;
    private FactBook mFactBook = new FactBook();
    private ColorWheel mColorWheel= new ColorWheel();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fun_facts);

    //Assign the views from the layout file to corresponding variables
    mRelativeLayout = (RelativeLayout) findViewById(R.id.factRelativeLayout);
    mFactTextView = (TextView) findViewById(R.id.factTextView);
    mShowFactButton = (Button) findViewById(R.id.showFactButton);


    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String fact = mFactBook.getFact();
            int color = mColorWheel.getColor();

            //Update the screen with our dynamic fact
            mFactTextView.setText(fact);

            //Update the background color
            mRelativeLayout.setBackgroundColor(color);

        }
    };
    mShowFactButton.setOnClickListener(listener);

}

}

Dariusz G贸rski
Dariusz G贸rski
5,515 Points

package com.example.darek.funfacts;

import java.util.Random;

/**

  • Created by Darek on 12.07.2016. */ public class FactBook {

    private String[] mFacts ={ "Ants stretch when they wake up in the morning.", "Ostriches can run faster than horses.", "Olympic gold medals are actually made mostly of silver.", "You are born with 300 bones; by the time you are an adult you will have 206.", "It takes about 8 minutes for light from the Sun to reach Earth.", "Some bamboo plants can grow almost a meter in just one day.", "The state of Florida is bigger than England.", "Some penguins can leap 2-3 meters out of the water.", "On average, it takes 66 days to form a new habit.", "Mammoths still walked the earth when the Great Pyramid was being built." };

    public String getFact(){

    // The button was clicked so update the fact TextView with a new fact
    String fact = "";
    //Randomly select a fact
    Random randomGenerator = new Random();
    int randomNumber = randomGenerator.nextInt(mFacts.length);
    fact = mFacts[randomNumber];
    
    return fact;
    

    };

}

Dariusz G贸rski
Dariusz G贸rski
5,515 Points

package com.example.darek.funfacts;

import android.graphics.Color;

import java.util.Random;

/**

  • Created by Darek on 13.07.2016. */ public class ColorWheel {

    public String[] mColors = { "#39add1", // light blue "#3079ab", // dark blue "#c25975", // mauve "#e15258", // red "#f9845b", // orange "#838cc7", // lavender "#7d669e", // purple "#53bbb4", // aqua "#51b46d", // green "#e0ab18", // mustard "#637a91", // dark gray "#f092b0", // pink "#b7c0c7" // light gray };

    public int getColor(){ String color;

    Random randomGenerator = new Random();
    int randomNumber = randomGenerator.nextInt(mColors.length);
    color = mColors[randomNumber];
    
    int colorAsInt = Color.parseColor(color);
    
    return colorAsInt;
    

    } }

Dariusz G贸rski
Dariusz G贸rski
5,515 Points

I found at google that it may have some connection with AndroidManifest.xml so I will add it here aswell: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.darek.funfacts">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".FunFactsActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

And styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

Hope that someone is able to help me figure it out. Thanks in advance!

Seth Kroger
Seth Kroger
56,413 Points

This one's a head-scratcher. Can you try a clean and rebuild (under the Build menu)? Also double-check that your Java are in the main source folder, not either of the test folders.