1

Everything was working fine but when i added a new activity to my project and run the app in emulator, it first gives an error "unfortunately, app is not working" , and then the app starts again and works fine. following is my logCat data

09-29 14:42:42.929: E/Trace(854): error opening trace file: No such file or directory (2)
09-29 14:42:43.359: D/dalvikvm(854): GC_FOR_ALLOC freed 30K, 7% free 2401K/2576K, paused 164ms,        total 166ms
09-29 14:42:43.468: I/dalvikvm-heap(854): Grow heap (frag case) to 5.778MB for 3456016-byte   allocation
09-29 14:42:43.568: D/dalvikvm(854): GC_FOR_ALLOC freed <1K, 3% free 5775K/5952K, paused 100ms, total 100ms
09-29 14:42:43.689: D/dalvikvm(854): GC_CONCURRENT freed <1K, 3% free 5775K/5952K, paused 6ms+5ms, total 121ms
09-29 14:42:47.908: I/Choreographer(854): Skipped 71 frames!  The application may be doing too much work on its main thread.
09-29 14:42:48.488: D/gralloc_goldfish(854): Emulator without GPU emulation detected.
09-29 14:43:06.618: I/Choreographer(854): Skipped 32 frames!  The application may be doing too much work on its main thread.
09-29 14:43:08.598: I/Choreographer(854): Skipped 34 frames!  The application may be doing too much work on its main thread.
09-29 14:43:11.068: W/databse(854): reading from database
09-29 14:43:11.068: W/action(854): reading complete checking the cursor
09-29 14:43:12.139: D/dalvikvm(854): GC_CONCURRENT freed 203K, 5% free 6686K/7028K, paused  110ms+67ms, total 528ms
09-29 14:59:53.328: D/AndroidRuntime(1162): Shutting down VM
09-29 14:59:53.328: W/dalvikvm(1162): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-29 14:59:53.378: E/AndroidRuntime(1162): FATAL EXCEPTION: main
09-29 14:59:53.378: E/AndroidRuntime(1162): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.os.Looper.loop(Looper.java:137)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at java.lang.reflect.Method.invoke(Method.java:511)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at dalvik.system.NativeStart.main(Native Method)
09-29 14:59:53.378: E/AndroidRuntime(1162): Caused by: java.lang.NullPointerException
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:379)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.LoadedApk.getClassLoader(LoadedApk.java:322)
09-29 14:59:53.378: E/AndroidRuntime(1162):     at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
09-29 14:59:53.378: E/AndroidRuntime(1162):     ... 11 more
09-29 15:00:01.938: D/dalvikvm(1194): GC_FOR_ALLOC freed 46K, 8% free 2453K/2644K, paused 43ms, total 47ms
09-29 15:00:01.969: I/dalvikvm-heap(1194): Grow heap (frag case) to 5.829MB for 3456016-byte allocation
09-29 15:00:02.028: D/dalvikvm(1194): GC_FOR_ALLOC freed 2K, 4% free 5826K/6020K, paused 55ms, total 55ms
09-29 15:00:02.099: D/dalvikvm(1194): GC_CONCURRENT freed <1K, 4% free 5826K/6020K, paused 4ms+5ms, total 70ms
09-29 15:00:03.978: I/Choreographer(1194): Skipped 77 frames!  The application may be doing too much work on its main thread.
09-29 15:00:04.449: D/gralloc_goldfish(1194): Emulator without GPU emulation detected.
09-29 15:00:10.818: I/Choreographer(1194): Skipped 45 frames!  The application may be doing too much work on its main thread.
09-29 15:00:15.018: W/databse(1194): reading from database
09-29 15:00:15.018: W/action(1194): reading complete checking the cursor
09-29 15:00:16.008: D/dalvikvm(1194): GC_CONCURRENT freed 196K, 5% free 6683K/7024K, paused 79ms+79ms, total 476ms
09-29 16:32:38.378: D/AndroidRuntime(1335): Shutting down VM
09-29 16:32:38.398: W/dalvikvm(1335): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-29 16:32:38.408: E/AndroidRuntime(1335): FATAL EXCEPTION: main
09-29 16:32:38.408: E/AndroidRuntime(1335): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.os.Looper.loop(Looper.java:137)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at java.lang.reflect.Method.invoke(Method.java:511)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at dalvik.system.NativeStart.main(Native Method)
09-29 16:32:38.408: E/AndroidRuntime(1335): Caused by: java.lang.NullPointerException
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:379)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.LoadedApk.getClassLoader(LoadedApk.java:322)
09-29 16:32:38.408: E/AndroidRuntime(1335):     at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
09-29 16:32:38.408: E/AndroidRuntime(1335):     ... 11 more
09-29 16:32:48.109: E/Trace(1410): error opening trace file: No such file or directory (2)
09-29 16:32:48.930: D/dalvikvm(1410): GC_CONCURRENT freed 57K, 7% free 2751K/2956K, paused 78ms+5ms, total 304ms
09-29 16:32:48.930: D/dalvikvm(1410): WAIT_FOR_CONCURRENT_GC blocked 171ms
09-29 16:32:49.079: D/dalvikvm(1410): GC_FOR_ALLOC freed 360K, 17% free 2608K/3112K, paused 32ms, total 34ms
09-29 16:32:49.109: I/dalvikvm-heap(1410): Grow heap (frag case) to 5.979MB for 3456016-byte allocation
09-29 16:32:49.169: D/dalvikvm(1410): GC_FOR_ALLOC freed <1K, 8% free 5982K/6488K, paused 55ms, total 55ms
09-29 16:32:49.238: D/dalvikvm(1410): GC_CONCURRENT freed <1K, 8% free 5982K/6488K, paused 5ms+5ms, total 76ms
09-29 16:32:51.488: I/Choreographer(1410): Skipped 63 frames!  The application may be doing too much work on its main thread.
09-29 16:32:51.900: I/Choreographer(1410): Skipped 35 frames!  The application may be doing too much work on its main thread.
09-29 16:32:51.979: D/gralloc_goldfish(1410): Emulator without GPU emulation detected.
09-29 16:33:24.198: I/Choreographer(1410): Skipped 31 frames!  The application may be doing too much work on its main thread.
09-29 16:33:25.812: I/Choreographer(1410): Skipped 32 frames!  The application may be doing too much work on its main thread.
09-29 16:36:04.918: I/Choreographer(1410): Skipped 31 frames!  The application may be doing too much work on its main thread.

MainPage.Class

    package com.smarttrack;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class MainPage extends Activity implements OnClickListener{

    ImageView img;
    TextView statusText;
    String status ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_page);
        initVars();
        img.setOnClickListener(this);


    }
    private void initVars() {
        // TODO Auto-generated method stub
        img = (ImageView)findViewById(R.id.switchingImage);
        statusText = (TextView)findViewById(R.id.appStatus);
        img.setImageResource(R.drawable.switch_off);
        status = "active";


    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        int id = v.getId();

        switch(id){
        case R.id.switchingImage:
            Runnable swap = new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    if(status == "active"){
                        img.setImageResource(R.drawable.switch_off);
                        statusText.setText("Status = Running");
                        status = "unactive";
                    }else {
                        img.setImageResource(R.drawable.switch_on);
                        statusText.setText("Status = Stopped");
                        status = "active";
                    }
                }

            };
            img.postDelayed(swap, 100);
            break;
        }
    }



}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smarttrack"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:theme="@style/ActionBarTheme" >
        <activity
            android:name="com.smarttrack.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>
          <activity
            android:name="com.smarttrack.LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
          <activity
            android:name="com.smarttrack.MainPage"
            android:label="@string/app_name" 
            android:theme="@style/ActionBarTheme"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
waqas
  • 19
  • 2
  • 8

2 Answers2

0

You declare a new Activity on AndroidManifest.xml ?

Same problem was happening to me, and it was not the statement of activity.

Regrards

0

In your AndroidManifest.xml file, you have declared your main Activity as:

android:name="com.smarttrack.MainActivity"

But in your codes, your main Activity is declared as:

public class MainPage extends Activity implements OnClickListener {
    // Codes here.
}

Either change them both to MainPage or MainActivity.

  • the MainPage activity is listed at the end of manifest file MainActivity is a seaparate activity – waqas Sep 29 '14 at 19:59
  • I saw that. What I am saying though is why you have both MainActivity and MainPage in your `AndroidManifest` file. Maybe an explanation about the activities might help explained what you're trying to do so we can help you. –  Sep 30 '14 at 07:53