• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps error! the app stopped working unexpectedly

i've finished a tutorial teaching the basics of android development. during the tutorial i made a moneyconverter. very basic but good for teaching. no errors are showing up in the problem tab etc. but when i try to run the app in the emulator it will crash and leave me the following message :

sorry! the application MoneyConverter (process EasyApp.moneyconverter) has stopped unexpectedly. please try again.

I've searched the internet for a solution but couldn't find anything useful for me.
I hope someone can help me and explain the solution so that a beginning android developer can execute it. if you need more info than I'm posting below let me know.

thx in advance,
Olijf

the info:

error message:
sorry! the application MoneyConverter (process EasyApp.moneyconverter) has stopped unexpectedly. please try again!

logcat:

09-24 18:47:54.264: D/ddm-heap(210): Got feature list request
09-24 18:47:54.844: D/AndroidRuntime(210): Shutting down VM
09-24 18:47:54.844: W/dalvikvm(210): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
09-24 18:47:54.844: E/AndroidRuntime(210): Uncaught handler: thread main exiting due to uncaught exception
09-24 18:47:54.894: E/AndroidRuntime(210): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{EasyApp.moneyconverter/EasyApp.moneyconverter.MoneyConverter}: java.lang.ClassNotFoundException: EasyApp.moneyconverter.MoneyConverter in loader dalvik.system.PathClassLoader@44c068f0
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2417)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2512)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread.access$2200(ActivityThr ead.java:119)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread$H.handleMessage(Activit yThread.java:1863)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.os.Handler.dispatchMessage(Handler.java:99 )
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.os.Looper.loop(Looper.java:123)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread.main(ActivityThread.jav a:4363)
09-24 18:47:54.894: E/AndroidRuntime(210): at java.lang.reflect.Method.invokeNative(Native Method)
09-24 18:47:54.894: E/AndroidRuntime(210): at java.lang.reflect.Method.invoke(Method.java:521)
09-24 18:47:54.894: E/AndroidRuntime(210): at com.Android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:860)
09-24 18:47:54.894: E/AndroidRuntime(210): at com.Android.internal.os.ZygoteInit.main(ZygoteInit .java:618)
09-24 18:47:54.894: E/AndroidRuntime(210): at dalvik.system.NativeStart.main(Native Method)
09-24 18:47:54.894: E/AndroidRuntime(210): Caused by: java.lang.ClassNotFoundException: EasyApp.moneyconverter.MoneyConverter in loader dalvik.system.PathClassLoader@44c068f0
09-24 18:47:54.894: E/AndroidRuntime(210): at dalvik.system.PathClassLoader.findClass(PathClassL oader.java:243)
09-24 18:47:54.894: E/AndroidRuntime(210): at java.lang.ClassLoader.loadClass(ClassLoader.java:5 73)
09-24 18:47:54.894: E/AndroidRuntime(210): at java.lang.ClassLoader.loadClass(ClassLoader.java:5 32)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.Instrumentation.newActivity(Instrument ation.java:1021)
09-24 18:47:54.894: E/AndroidRuntime(210): at Android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2409)
09-24 18:47:54.894: E/AndroidRuntime(210): ... 11 more
09-24 18:47:54.974: I/dalvikvm(210): threadid=7: reacting to signal 3
09-24 18:47:54.974: E/dalvikvm(210): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
 

Attachments

  • Naamloos.png
    Naamloos.png
    210 KB · Views: 57
  • Naamloos1.png
    Naamloos1.png
    291.3 KB · Views: 82
The most probable reason for this is that you haven't defined your Activity properly in the AndroidManifest.xml

this is my manifest. anything suspicious in here?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="EasyApp.moneyconverter"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MoneyConverter"
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>
 
Upvote 0
The manifest looks OK. Could you also post the Java Source Code?

And have a look at this StackOverflow question.

MainActivity.java:

package EasyApp.moneyconverter;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {

EditText mEtxtAmount;
Button mBtnCalculate;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEtxtAmount = (EditText) findViewById(R.id.etxtAmount);
mBtnCalculate = (Button) findViewById(R.id.btnCalculate);
}

public void calculateToDollars(View view){
float euros = Float.valueOf(mEtxtAmount.getText().toString());
float dollars = (float) 1.36 * euros;
Toast.makeText(this, "
 
Upvote 0
The name of the Activity in your source code is MainActivity, but in your manifest file, you declare the Activity as MoneyConverter.

In your source code, change your class name to MoneyConverter and it should work.
i see what you mean. but how do i do this?

public class MainActivity extends Activity {
to
prublic class MoneyConverter extends Activity {
?

but if you mean to change the MainActivity.java file to MoneyConverter.java i need some step by step help. because i can't find it.
i'm still a newbie.
 
Upvote 0
that didn't work also. very frustrating. i'll post the full project so you can have a look over to see if you find anything strange. you're my last hope. can't find anything useful on the internet also, most people got the same error but with another cause.

i noticed the last lines in the logcat. i googled it, it might be something with the sdcard or premissions of using it.

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/btnCalculate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:eek:nClick="calculateToDollars" >

<EditText
android:id="@+id/etxtAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="130dp"
android:ems="10"
android:inputType="numberDecimal" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/etxtAmount"
android:layout_centerHorizontal="true"
android:text="@string/btnCalculate" />

</RelativeLayout>


MoneyConverter.java :

package EasyApp.moneyconverter;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;

public class MoneyConverter extends Activity {

EditText mEtxtAmount;
Button mBtnCalculate;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEtxtAmount = (EditText) findViewById(R.id.etxtAmount);
mBtnCalculate = (Button) findViewById(R.id.btnCalculate);
}

public void calculateToDollars(View view){
float euros = Float.valueOf(mEtxtAmount.getText().toString());
float dollars = (float) 1.36 * euros;
Toast.makeText(this, "
 
Upvote 0
The first error has been solved, however you now have a different error:
You are trying to cast a RelativeLayout to a Button.

In your activity_main.xml, you give your parent RelativeLayout and id of btnCalculate, and in onCreate, you have:
Code:
mBtnCalculate = (Button) findViewById(R.id.btnCalculate);

The above code should be changed to
Code:
mBtnCalculate = (Button) findViewById(R.id.etxtAmount);

since Your Button has been given an id of eTxtAmount, NOT btnCalculate.
 
Upvote 0
The first error has been solved, however you now have a different error:
You are trying to cast a RelativeLayout to a Button.

In your activity_main.xml, you give your parent RelativeLayout and id of btnCalculate, and in onCreate, you have:
Code:
mBtnCalculate = (Button) findViewById(R.id.btnCalculate);
The above code should be changed to
Code:
mBtnCalculate = (Button) findViewById(R.id.etxtAmount);
since Your Button has been given an id of eTxtAmount, NOT btnCalculate.

that didn't solve the problem also. it did decrease the logcat...

logcat:

09-26 10:16:31.630: D/AndroidRuntime(225): Shutting down VM
09-26 10:16:31.630: W/dalvikvm(225): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
09-26 10:16:31.630: E/AndroidRuntime(225): Uncaught handler: thread main exiting due to uncaught exception
09-26 10:16:31.639: E/AndroidRuntime(225): java.lang.RuntimeException: Unable to start activity ComponentInfo{EasyApp.moneyconverter/EasyApp.moneyconverter.MoneyConverter}: java.lang.ClassCastException: android.widget.RelativeLayout
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.os.Looper.loop(Looper.java:123)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-26 10:16:31.639: E/AndroidRuntime(225): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 10:16:31.639: E/AndroidRuntime(225): at java.lang.reflect.Method.invoke(Method.java:521)
09-26 10:16:31.639: E/AndroidRuntime(225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-26 10:16:31.639: E/AndroidRuntime(225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-26 10:16:31.639: E/AndroidRuntime(225): at dalvik.system.NativeStart.main(Native Method)
09-26 10:16:31.639: E/AndroidRuntime(225): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
09-26 10:16:31.639: E/AndroidRuntime(225): at EasyApp.moneyconverter.MoneyConverter.onCreate(MoneyConverter.java:21)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-26 10:16:31.639: E/AndroidRuntime(225): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
09-26 10:16:31.639: E/AndroidRuntime(225): ... 11 more
09-26 10:16:31.669: I/dalvikvm(225): threadid=7: reacting to signal 3
09-26 10:16:31.669: E/dalvikvm(225): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
 
Upvote 0
Your layout is still not correct:

Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/btnCalculate"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:onClick="calculateToDollars" >

The id of the RelativeLayout shouldn't be btnCalculate. You are probably using the same id twice, which is of course wrong. Change the id or remove it completely, since you aren't referencing it from code.
 
  • Like
Reactions: olijf
Upvote 0
Oops... Sorry, I misread your XML...
It should be changed to:
Code:
mBtnCalculate = (Button) findViewById(R.id.button1);

the problem is solved :D.
no more errors. only thing to be solved is the button to respond. nothing is happening now, but I'll do that myself as a good practise.

thx for the effort and your time guys.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones