Reputation: 21
Im new to android development ,im just following tutorials so while running project as android application on emulator it is showing "your application has stopped unfortunately". I have seen so many answers in stackoverflow but didn't get solution. I went to logcat also . what I have done just simply run my hello world in emulator but it was stopped.
1) this is my xml 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="com.examp.calc.MainActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textSize="40sp" />
</RelativeLayout>
2) Java source code : activity file
package com.examp.calc;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}}
3)Mainfest file
`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examp.calc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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>
</application>
</manifest>
`
4)logcat error report:
03-10 06:56:55.347: D/AndroidRuntime(1761): Shutting down VM 03-10 06:56:55.347: W/dalvikvm(1761): threadid=1: thread exiting with ncaught exception (group=0xb0d77b20) 03-10 06:56:55.347: E/AndroidRuntime(1761): FATAL EXCEPTION: main 03-10 06:56:55.347: E/AndroidRuntime(1761): Process: com.examp.calc, PID: 1761 03-10 06:56:55.347: E/AndroidRuntime(1761): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.examp.calc/com.exam.calc.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.exam.calc.MainActivity" on path: DexPathList[[zip file "/data/app/com.examp.calc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.examp.calc-1, /system/lib]] 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread.access$800(ActivityThread.java:135) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.os.Handler.dispatchMessage(Handler.java:102) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.os.Looper.loop(Looper.java:136) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread.main(ActivityThread.java:5017) 03-10 06:56:55.347: E/AndroidRuntime(1761): at java.lang.reflect.Method.invokeNative(Native Method) 03-10 06:56:55.347: E/AndroidRuntime(1761): at java.lang.reflect.Method.invoke(Method.java:515) 03-10 06:56:55.347: E/AndroidRuntime(1761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 03-10 06:56:55.347: E/AndroidRuntime(1761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-10 06:56:55.347: E/AndroidRuntime(1761): at dalvik.system.NativeStart.main(Native Method) 03-10 06:56:55.347: E/AndroidRuntime(1761): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.exam.calc.MainActivity" on path: DexPathList[[zip file "/data/app/com.examp.calc-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.examp.calc-1, /system/lib]] 03-10 06:56:55.347: E/AndroidRuntime(1761): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 03-10 06:56:55.347: E/AndroidRuntime(1761): at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 03-10 06:56:55.347: E/AndroidRuntime(1761): at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.Instrumentation.newActivity(Instrumentation.java:1061) 03-10 06:56:55.347: E/AndroidRuntime(1761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112) 03-10 06:56:55.347: E/AndroidRuntime(1761): ... 11 more
5) after debugging : source not found in debug thank you advance
Upvotes: 0
Views: 249
Reputation: 3971
Try changing your extends ActionBarActivity
by extends Activity
.
The compiler search for the package com.exam.calc but your package name is com.examp.calc.
In your Manifest
, replace :
android:name="com.exam.calc.MainActivity"
By :
android:name="com.examp.calc.MainActivity"
If it's not working, you can try this...
Try deleting this line in your xml layout :
tools:context="com.examp.calc.MainActivity"
You should have :
<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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textSize="40sp" />
</RelativeLayout>
Or if you prefer, you can delete the setContentView
line of your Activity
.
Upvotes: 0
Reputation: 4157
In Mainfest file : change this line
android:name="com.examp.calc.MainActivity"
Upvotes: 0
Reputation: 659
You must not define;
tools:context="com.examp.calc.MainActivity"
and
setContentView(R.layout.activity_main);
at the same time. Just remove one of them and it will work properly.
Upvotes: 1