Reputation: 170
Intent intent = new Intent();
intent.setClass(MainActivity.this, Line.class);
startActivity(intent);
My cellphone alert "Sorry,The program has stopped working".
Why?
This is the error. http://www.mgiga.com.tw:8080/mo/01.jsp
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="com.sample.activity.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Upvotes: 1
Views: 130
Reputation: 24848
Try this way,hope this will help you to solve your problem.
Intent intent = new Intent();
intent.setClass(MainActivity.this, "YourPackageName.Line");
startActivity(intent);
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Line"/>
</application>
</manifest>
Upvotes: 0
Reputation: 6162
Line
is an Activity
you haven't declare it inside manifest
. Thats why you get ActivityNotFoundException.
Edit :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="com.sample.activity.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.dragimagedemo.Line" >
</activity>
</application>
Upvotes: 0
Reputation: 5011
May be there is some problem in your second activity("Line.class") not in button click. Make another demo activity with "hello world" & check that still your app crashes or not. Example: if your demo activity named "DemoActivity
" Then write code
Intent intent = new Intent(MainActivity.this, DemoActivity.class);
startActivity(intent);
If you give Logcat error then it is better understandable for us.
Edited: add activity in your manifest.xml
<activity
android:name="YourPackageName.Line"
android:label="@string/app_name">
Upvotes: 0
Reputation: 897
Best if you could share the error you get in your logcat
Intent intent = new Intent(MainActivity.this, Line.class);
startActivity(intent);
Because your program can crash because of a lot of reasons.
Upvotes: 4