Hello i'm new to android programming, this application crashes after the it encounters the startActivity() call, there are two buttons which have which when pressed launch new activities one of them works fine but by pressing the other the application crashes, i have defined them in the AndroidManifest.xml. I have commented the code which results in crash.
public class poetry extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.poetry);
WindowManager wm = getWindowManager();
Display d = wm.getDefaultDisplay();
if(d.getWidth() > d.getHeight()){
Log.d("Orientation", "Landscape");
}else{
Log.d("Orientation", "Potratit");
}
}
//Results in crash
public void onClickPersian(View v){
startActivity(new Intent(poetry.this, persian.class));
}
//Runs Fine
public void onClickUrdu(View v){
startActivity(new Intent(poetry.this, urdu.class));
}
}
Class Persian
public class persian extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.persian);
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
if(d.getWidth() > d.getHeight()){
Log.d("Orientation", "Landscape");
}else{
Log.d("Orientation", "Potrait");
}
}
}
Persian.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">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Persian"
android:id="@+id/btnPersian"
android:layout_centerHorizontal="true"
android:layout_marginTop="@android:dimen/app_icon_size"
android:onClick="onClickPersian"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Urdu"
android:id="@+id/btnUrdu"
android:layout_centerHorizontal="true"
android:layout_below="@+id/btnPersian"
android:layout_marginTop="25dp"
android:onClick="onClickUrdu"
/>
</RelativeLayout>
AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ZindaRud"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="14"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@android:style/Theme.Holo.Light">
<activity android:name=".main"
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=".poetry"
android:label="@string/Poetry">
</activity>
<activity android:name=".prose"
android:label="@string/RRI">
</activity>
<activity android:name=".biography"
android:label="@string/Biography">
</activity>
<actvity android:name=".persian"
android:label="@string/persianPoetry">
</actvity>
<activity android:name="urdu"
android:label="@string/urduPoetry">
</activity>
<activity android:name=".preface"
android:label="@string/Preface">
</activity>
</application>
</manifest>
The application crashes when the onClickPersian method is launched.
LogCat:
06-26 15:34:23.407 745-745/com.example.ZindaRud D/Orientation﹕ Potratit
06-26 15:34:24.967 745-745/com.example.ZindaRud D/AndroidRuntime﹕ Shutting down VM
06-26 15:34:24.967 745-745/com.example.ZindaRud W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-26 15:34:25.017 745-745/com.example.ZindaRud E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3039)
at android.view.View.performClick(View.java:3480)
at android.view.View$PerformClick.run(View.java:13983)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3034)
at android.view.View.performClick(View.java:3480)
at android.view.View$PerformClick.run(View.java:13983)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.ZindaRud/com.example.ZindaRud.persian}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
at android.app.Activity.startActivityForResult(Activity.java:3190)
at android.app.Activity.startActivity(Activity.java:3297)
at com.example.ZindaRud.poetry.onClickPersian(poetry.java:28)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3034)
at android.view.View.performClick(View.java:3480)
at android.view.View$PerformClick.run(View.java:13983)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)