1

Answered(at bottom)

So I have been trying to get my button to allow me to go to the next screen. I am programming in eclipse. It is a basic login button to allow me to go to the login screen. I apologize for the long post, but I feel that giving all the information I have right now is good.

I am wondering if it is my device I am using it to run on when I press play.

The error at the bottom of my logcat is:

(The first few lines of logcat)

11-06 18:08:59.973: PID 324 TID 324 D/AndroidRuntime(324): Shutting down VM
11-06 18:08:59.973: W/dalvikvm(324): threadid=1: thread exiting with uncaught exception     
(group=0x4001d800)
11-06 18:08:59.983: E/AndroidRuntime(324): FATAL EXCEPTION: main
11-06 18:08:59.983: E/AndroidRuntime(324): android.content.ActivityNotFoundException: Unable to 
find explicit activity class {com.example.coffeeshop/com.example.coffeeshop.Login}; have you 
declared this activity in your AndroidManifest.xml?

Those are the first few lines as it goes to error.

So my res/layout/activity_main code: (Please note that the second button for "Create account" is not going to be an issue I am trying to get the login to go to the login screen.)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".Main"
    android:background="#15BCA8"
    android:id="@+id/activity_main">
<Button
    android:id="@+id/createbtn"
    android:layout_width="2200dp"
    android:layout_height="70dp"
    android:padding="10dp"
    android:textSize="25sp"
    android:textStyle="bold|normal"
    android:text="@string/create_account"
    android:textColor="#000000"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="44dp"
    android:background="@drawable/roundedbutton" />
<Button
    android:id="@+id/loginbtn"
    android:layout_width="2200dp"
    android:layout_height="80dp"
    android:layout_above="@+id/createbtn"
    android:layout_alignStart="@+id/createbtn"
    android:layout_alignLeft="@+id/createbtn"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="29dp"
    android:padding="10dp"
    android:text="@string/log_in"
    android:textColor="#000000"
    android:textSize="30sp"
    android:textStyle="bold|normal"
    android:typeface="sans"
    android:background="@drawable/roundedbutton"
    />
</RelativeLayout>

And this layout is suppose to lead to the login.xml. Also, the roundedbutton will be posted at the end, but I don't think it's an issue. login.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#15BCA8"
android:id="@+id/loginlayout">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="60sp"
    android:text="Login"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="61dp" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Username"
    android:id="@+id/button"
    android:textColor="#000000"
    android:background="#15BCA8"
    android:layout_marginTop="65dp"
    android:layout_toStartOf="@+id/textView"
    android:layout_below="@+id/textView"
    android:layout_toLeftOf="@+id/textView" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Password"
    android:id="@+id/button2"
    android:textColor="#000000"
    android:background="#15BCA8"
    android:layout_marginTop="58dp"
    android:layout_below="@+id/editText"
    android:layout_alignLeft="@+id/button"
    android:layout_alignStart="@+id/button" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/editText"
    android:layout_below="@+id/button"
    android:layout_alignLeft="@+id/button2"
    android:layout_alignStart="@+id/button2"
    android:background="#FFFFFF" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/editText2"
    android:layout_below="@+id/button2"
    android:layout_alignLeft="@+id/button2"
    android:layout_alignStart="@+id/button2"
    android:background="#FFFFFF" />

<Button
    android:id="@+id/sbmtbtn"
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/editText2"
    android:layout_alignRight="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="20dp"
    android:background="@drawable/roundedbutton"
    android:text="Submit"
    android:textSize="24sp" />

</RelativeLayout>

So this seems relatively fine, yeah?

Here is my MainActivity.java class:

package com.example.coffeeshop;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


    public class MainActivity  extends Activity {

    Button button;

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

    private void addListenerOnButton() {

        final Context context = this;

        button = (Button) findViewById(R.id.loginbtn);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, Login.class);
                startActivity(intent);

            }

        });
    }
}

And should link me to my login screen, coded here:

package com.example.coffeeshop;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Login  extends Activity {

    Button button;

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

    private void addListenerOnButton() {

        final Context context = this;

        button = (Button) findViewById(R.id.sbmtbtn);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(context, MainMenu.class);
                startActivity(intent);
            }
        });
    }
}

And for fun, here is my "roundedbutton.xml" file being called upon by my xml files. Which shouldn't have an issue here.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle" android:padding="10dp">   
 <!--  solid android:color="#834672"--> 
 <gradient android:startColor="#834672" 
           android:endColor="#718C93"
           android:angle="270" />
<stroke android:width="5px" android:color="#06302F" />
<corners android:radius="10dp"/>
</shape>

Now I can not understand why my program crashes.

Ok. I now have an answer that has worked out for me. I was not aware of the manifest, which was instantly solved with the code that "fast snail" left in his answer.

9
  • show the error.did you add activity to manifest ? Nov 7, 2014 at 0:13
  • 1
    When reporting an Android crash the most important thing to include is the output of logcat (see one of the tabs in the bottom third or your eclipse IDE)
    – German
    Nov 7, 2014 at 0:17
  • @German Thanks, I updated this will the error, sorry about that, still learning proper stackoverflow question etiquette.
    – Gary C
    Nov 7, 2014 at 0:28
  • The disconnected issue is the device issue. Which device you are connecting and on which platform. Does it used to work before? You might need a driver based on platform you are doing development on. Nov 7, 2014 at 0:42
  • 2
    No problem. But the logcat is incomplete. Try to run the app again while connected to your computer and see ig the logcat outputs more info. Specifically you're looking for an error in your app with an Exception saying that something went wrong
    – German
    Nov 7, 2014 at 0:42

2 Answers 2

2

based on your logcat, the problem is that you haven't defined your activity in manifest file.

The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. before the app runs the system must know which activities are there in your app, and it knows via manifest file. and if you miss any activity in manifest file then system assumes that the activity doesnt exist. now, when app runs it points to some activity that is not recognized by the system. hence, it crashes. you can read more about android manifest file here http://developer.android.com/guide/topics/manifest/manifest-intro.html

i cannot upvote else i would go with @fast snail's answer,i think that will solve your problem.

1
  • I agree, and thanks for the information. I still have to update it. But this should do it.
    – Gary C
    Nov 7, 2014 at 4:59
1

well

ActivityNotFoundException

that mean you have not declare this activity in AndroidManifest file.you need to declare all activities in manifest file

error exactly says you the problem

find explicit activity class {com.example.coffeeshop/com.example.coffeeshop.Login}; have you 
declared this activity in your AndroidManifest.xml?

add this line to manifest file

 <activity android:name=".Login"></activity>

finaly manifest should looks like// example

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.coffeeshop">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity" android:label="@string/app_name"></activity>

        <activity android:name=".Login"></activity> <!--add this line -->

    </application>
</manifest>
2
  • 1
    hey man. Thanks! I see what you're saying now. I am new to android development, so I appreciate your patience. I'm at work right now so I'll update it when I get home and report back as I soon as I can. Thanks again.
    – Gary C
    Nov 7, 2014 at 4:58
  • 1
    I got it to work with that, I've added it to other activities as well. It all works. Greatly appreciated. I am going to keep this post up and update it later on and work on it some more.
    – Gary C
    Nov 7, 2014 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.