Reputation: 19
I am doing a simple application: when I click on Button
take me to next Activity
.
The problem is that when I run the emulator and click on the Button
it pops a message
unfrotunately < app name> has stopped
Here is my code:
Main activity:
package learn2develop.uingintent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view){
startActivity(new Intent("learn2develop.uingintent.Secondd"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
second activity called : Secondd
package learn2develop.uingintent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Secondd extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondd);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.secondd, menu);
return true;
}
}
And this is my xml file of the main activity
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="50dp"
android:layout_toRightOf="@+id/textView1"
android:text="go"
android:onClick="onClick" />
</RelativeLayout>
Here is the log cat:
03-10 03:10:54.574: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:55.066: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:55.256: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:55.315: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:55.735: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:55.834: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:56.114: D/libEGL(564): loaded /system/lib/egl/libGLES_android.so
03-10 03:10:56.187: D/libEGL(564): loaded /system/lib/egl/libEGL_emulation.so
03-10 03:10:56.206: D/(564): HostConnection::get() New Host Connection established 0x18c178, tid 564
03-10 03:10:56.246: D/libEGL(564): loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-10 03:10:56.287: D/libEGL(564): loaded /system/lib/egl/libGLESv2_emulation.so
03-10 03:10:56.325: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:56.434: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:56.585: W/EGL_emulation(564): eglSurfaceAttrib not implemented
03-10 03:10:56.684: D/OpenGLRenderer(564): Enabling debug mode 0
03-10 03:10:56.764: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:56.834: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:57.274: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:57.314: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:10:57.814: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:10:57.866: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:11:18.103: D/AndroidRuntime(564): Shutting down VM
03-10 03:11:18.103: W/dalvikvm(564): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-10 03:11:18.176: E/AndroidRuntime(564): FATAL EXCEPTION: main
03-10 03:11:18.176: E/AndroidRuntime(564): java.lang.IllegalStateException: Could not execute method of the activity
03-10 03:11:18.176: E/AndroidRuntime(564): at android.view.View$1.onClick(View.java:3044)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.view.View.performClick(View.java:3511)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.view.View$PerformClick.run(View.java:14105)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.os.Handler.handleCallback(Handler.java:605)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.os.Handler.dispatchMessage(Handler.java:92)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.os.Looper.loop(Looper.java:137)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-10 03:11:18.176: E/AndroidRuntime(564): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 03:11:18.176: E/AndroidRuntime(564): at java.lang.reflect.Method.invoke(Method.java:511)
03-10 03:11:18.176: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-10 03:11:18.176: E/AndroidRuntime(564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-10 03:11:18.176: E/AndroidRuntime(564): at dalvik.system.NativeStart.main(Native Method)
03-10 03:11:18.176: E/AndroidRuntime(564): Caused by: java.lang.reflect.InvocationTargetException
03-10 03:11:18.176: E/AndroidRuntime(564): at java.lang.reflect.Method.invokeNative(Native Method)
03-10 03:11:18.176: E/AndroidRuntime(564): at java.lang.reflect.Method.invoke(Method.java:511)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.view.View$1.onClick(View.java:3039)
03-10 03:11:18.176: E/AndroidRuntime(564): ... 11 more
03-10 03:11:18.176: E/AndroidRuntime(564): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.salah.SecondActivity }
03-10 03:11:18.176: E/AndroidRuntime(564): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.app.Activity.startActivityForResult(Activity.java:3190)
03-10 03:11:18.176: E/AndroidRuntime(564): at android.app.Activity.startActivity(Activity.java:3297)
03-10 03:11:18.176: E/AndroidRuntime(564): at com.example.salah.MainActivity.onClick(MainActivity.java:17)
03-10 03:11:18.176: E/AndroidRuntime(564): ... 14 more
03-10 03:11:19.154: I/dalvikvm(564): threadid=3: reacting to signal 3
03-10 03:11:19.193: I/dalvikvm(564): Wrote stack traces to '/data/anr/traces.txt'
03-10 03:11:24.534: I/Process(564): Sending signal. PID: 564 SIG: 9
Upvotes: 0
Views: 895
Reputation: 928
Problem is(was) at your AndroidManifest.xml file, simple by adding new activity will fix the problem.
<activity android:name=".Secondd"></activity>
Upvotes: 0
Reputation: 3318
The error is here:
startActivity(new Intent("learn2develop.uingintent.Secondd"));
Use:
Intent i = new Intent(this, Secondd.class);
startActivity(i);
You can create a new Intent with a string as a parameter like that, but it's more easily readable specifying which Activities to move to and from.
Upvotes: 1