AbhishekSaha
AbhishekSaha

Reputation: 745

Android Studio, error with intents

I'm using Android Studio to write and run my android application but I run into this error when I try to go from one activity to another via intent, I either get this error:

android.content.ActivityNotFoundException: Unable to find explicit activity class 
{com.example.rudrunk/junit.framework.Test}; have you declared this activity in your
AndroidManifest.xml?

or a NullPointerException if I use another intent.

My manifest file is below, but all the code comes from the IDE automatically, so I don't understand what's going on.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rudrunk"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:theme="@style/AppTheme" android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:debuggable="true" android:allowBackup="true">
    <activity android:label="@string/app_name" android:name="com.example.rudrunk.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:label="@string/title_activity_test" android:name="com.example.rudrunk.Test" />
    <activity android:label="@string/title_activity_drunk_test" android:name="com.example.rudrunk.DrunkTest" />
</application>

Java Code for intents:

    final Intent localIntent1 = new Intent(MainActivity.this, DrunkTest.class);
    final Intent localIntent2 = new Intent(MainActivity.this, Test.class);
    Button localButton1 = (Button)findViewById(R.id.maybe);
    Button localButton2 = (Button)findViewById(R.id.yes);

    localButton1.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View paramAnonymousView)
        {
            startActivity(localIntent1);
        }
    });

    localButton2.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        Intent localIntent = new Intent("android.intent.action.CALL");
          localIntent2.setData(Uri.parse("tel:16097212155"));
           startActivity(localIntent2);

      }
    });

Upvotes: 0

Views: 1442

Answers (1)

matiash
matiash

Reputation: 55380

Looks like Test.class is being resolved into junit.framework.Test instead of your Activity. This could be a wrong import (import junit.framework.Test;?) but the sure way to make it work would be to use the full class name, i.e.

new Intent(MainActivity.this, com.example.rudrunk.Test.class);

In any case, it should match the class name in the AndroidManifest file.

Upvotes: 1

Related Questions