mardi 27 mai 2014

Could not execute the method ofthe activity


Vote count:

0




I'm learning to use Eclipse and program Android apps. Im currently using this book and im following along and i keep getting a huge error! The app will run in the emulator but the second i click the button ,the app force closes :(


I've started the book over 3 times in attempt to catch an error i missed but im starting to get discouraged and would appreciate help!


This is the error i get on my log-----



05-27 22:06:26.933: E/AndroidRuntime(1776): FATAL EXCEPTION: main
05-27 22:06:26.933: E/AndroidRuntime(1776): java.lang.IllegalStateException: Could not execute method of the activity
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.view.View$1.onClick(View.java:3597)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.view.View.performClick(View.java:4202)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.view.View$PerformClick.run(View.java:17340)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.os.Handler.handleCallback(Handler.java:725)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.os.Handler.dispatchMessage(Handler.java:92)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.os.Looper.loop(Looper.java:137)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-27 22:06:26.933: E/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 22:06:26.933: E/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 22:06:26.933: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-27 22:06:26.933: E/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-27 22:06:26.933: E/AndroidRuntime(1776): at dalvik.system.NativeStart.main(Native Method)
05-27 22:06:26.933: E/AndroidRuntime(1776): Caused by: java.lang.reflect.InvocationTargetException
05-27 22:06:26.933: E/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 22:06:26.933: E/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.view.View$1.onClick(View.java:3592)
05-27 22:06:26.933: E/AndroidRuntime(1776): ... 11 more
05-27 22:06:26.933: E/AndroidRuntime(1776): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.helloworld/com.helloworld.Hello}; have you declared this activity in your AndroidManifest.xml?
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Activity.startActivityForResult(Activity.java:3370)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Activity.startActivityForResult(Activity.java:3331)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Activity.startActivity(Activity.java:3566)
05-27 22:06:26.933: E/AndroidRuntime(1776): at android.app.Activity.startActivity(Activity.java:3534)
05-27 22:06:26.933: E/AndroidRuntime(1776): at com.helloworld.MainActivity.helloload(MainActivity.java:18)
05-27 22:06:26.933: E/AndroidRuntime(1776): ... 14 more


Here is my MainActivity.java code----



package com.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
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 helloload(View view) {
Intent helloload = new Intent(MainActivity.this,Hello.class);
MainActivity.this.startActivity(helloload);
}
}


Here is my activity_main.xml code-----



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="186dp"
android:onClick="helloload"
android:text="Hello"/>
</RelativeLayout>


Here is my Hello.java code----



package com.helloworld;
import android.os.Bundle;
import android.app.Activity;
public class Hello extends Activity { @Override protected void onCreate( Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.hello);

}
}


Here is my hello.xml code-----



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</LinearLayout>


HERE IS my HelloWorld Manifest-----



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.helloworld.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>
</application>
</manifest>


ANYONE ABLE TO HELP ME WITH THIS ISSUE, PLEASE DO. I WANT TO KEEP CODING AND ENJOY ECLIPSE BUT IVE BEEN UNABLE TO GET PAST GETTING THIS BUTTON TO WORK AND THE EMULATOR CRASHING :(


Once i run the app and click the button the emulator states "It seems as if Hello World has stopped working" It runs, but when i click the button it force closes and i get the errors stated in the log above.


THANK YOU ALL!


-Colt



asked 34 secs ago






Aucun commentaire:

Enregistrer un commentaire