android app crashes on calling new activity

Hello,

i have an android app i am working on i am new to android so i have a new activity that i wanted to start that was an entry form but when i call the activity the app crashes on my phone

here is the code for the button call to open the activity
       // / / / / / / / / / / / / / / / / / / / / / /
        //Initialize forms of the ImageButtons
        // / / / / / / / / / / / / / / / / / / / / / /
        /* Button */
        ImageButton pcaButton = (ImageButton)findViewById(R.id.reg);

        // / / / / / / / / / / / / / / / / / / / / / /
        //Attach the Listener (On Click Event handler)
        // / / / / / / / / / / / / / / / / / / / / / /
        pcaButton.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this , Register.class);
                startActivity(intent);
            }
        });

Open in new window

LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
 
KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi Chris Jones,

Problem is within your manifest file. Edit your code something like this.

MainActivity.java

public class MainActivity extends Activity {

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

        ImageButton pcaButton = (ImageButton)findViewById(R.id.imageButton);
        pcaButton.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this , RegisterActivity.class);
                startActivity(intent);
            }
        });
    }
}

Open in new window


RegisterActivity.java

public class RegisterActivity extends Activity {

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


    }
}

Open in new window


AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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=".RegisterActivity" android:label="@string/app_name" />
        <!--<service android:enabled="true" android:name=".UartService" />-->

Open in new window



If you not get then let me know.

Thanks & Regards,
Krunal T. Tailor
1
 
Chris JonesLead Application Web DeveloperAuthor Commented:
any help would be awesome
0
 
KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi Chris Jones,

Can you please paste your Android manifest file code, because there you need to add activity of new view.
See this tutorial for ref: http://www.javatpoint.com/android-explicit-intent-example

Thanks & Regards,
Krunal T. Tailor
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
here is the manifest file.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.joneschris.joneschris_findme4" >

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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=".DeviceListActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Dialog"/>
        <service android:enabled="true" android:name=".UartService" />

        <activity android:name=".Register"/>
    </application>

</manifest>

Open in new window

0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
works great thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.