Android app won't launch on emulator - java

The debugger can't find anything wrong, and the app still won't launch: here is the the logcat and the code:
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
#SuppressLint("UseValueOf") public class MainActivity extends Activity {
protected Double value1;
protected Double value2;
protected Double value3;
protected Double delta;
protected Double x1;
protected Double x2;
final EditText tf1 = (EditText)findViewById(R.id.editText1);
final EditText tf2 = (EditText)findViewById(R.id.editText2);
final EditText tf3 = (EditText)findViewById(R.id.editText3);
final TextView result1 = (TextView) findViewById(R.id.textView4);
final TextView result2 = (TextView) findViewById(R.id.textView6);
final Button caculate = (Button) findViewById(R.id.button1);
#SuppressLint("UseValueOf") #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tf1.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus)
setTextToString1();
}
});
tf2.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus)
setTextToString2();
}
});
tf3.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
if(!hasFocus)
setTextToString3();
}
});
caculate.setOnClickListener(null);
{
if( !(value3.equals(null)&&value2.equals(null)&&value3.equals(null)) )
{
delta = new Double(caculateDelta(value1,value2,value3));
x1 = caculateX(Math.sqrt(delta.doubleValue()));
x2 =caculateX(-Math.sqrt(delta.doubleValue()));
result1.setText(x1.toString());
result2.setText(x2.toString());
}
else
{
result1.setText("Error");
result2.setText("Error");
}
}
}
public void setTextToString1()
{
value1 = new Double(Integer.parseInt(tf1.getText().toString()));
}
#SuppressLint("UseValueOf") public void setTextToString2()
{
value2 = new Double( Integer.parseInt(tf2.getText().toString()));
}
public void setTextToString3()
{
value3 = new Double( Integer.parseInt(tf3.getText().toString()));
}
public double caculateDelta (double a, double b , double c)
{
return b*b-(4*a*c);
}
public double caculateX (Double delta)
{
return (-value2+delta.doubleValue()/(2*value1));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and here is the logcat, i have deleted the whole logcat and restart the app
then coppied that logcat:
03-22 19:57:47.946: D/AndroidRuntime(788): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
03-22 19:57:47.946: D/AndroidRuntime(788): CheckJNI is ON
03-22 19:57:48.036: D/dalvikvm(788): Trying to load lib libjavacore.so 0x0
03-22 19:57:48.057: D/dalvikvm(788): Added shared lib libjavacore.so 0x0
03-22 19:57:48.135: D/dalvikvm(788): Trying to load lib libnativehelper.so 0x0
03-22 19:57:48.135: D/dalvikvm(788): Added shared lib libnativehelper.so 0x0
03-22 19:57:49.786: D/AndroidRuntime(788): Calling main entry com.android.commands.pm.Pm
03-22 19:57:49.916: I/ActivityManager(299): Start proc com.android.defcontainer for service com.android.defcontainer/.DefaultContainerService: pid=799 uid=10009 gids={50009, 1015, 2001, 1028}
03-22 19:57:50.176: E/Trace(799): error opening trace file: No such file or directory (2)
03-22 19:57:50.446: W/ActivityManager(299): No content provider found for permission revoke: file:///data/local/tmp/SqureFunC.apk
03-22 19:57:50.836: W/ActivityManager(299): No content provider found for permission revoke: file:///data/local/tmp/SqureFunC.apk
03-22 19:57:50.836: I/PackageManager(299): Copying native libraries to /data/app-lib/vmdl1616084389
03-22 19:57:51.416: I/PackageManager(299): Removing non-system package:com.eilonudi.squrefunc
03-22 19:57:51.416: I/ActivityManager(299): Force stopping package com.eilonudi.squrefunc appid=10046 user=-1
03-22 19:57:52.027: I/PackageManager(299): Package com.eilonudi.squrefunc codePath changed from /data/app/com.eilonudi.squrefunc-2.apk to /data/app/com.eilonudi.squrefunc-1.apk; Retaining data and using new
03-22 19:57:52.081: I/PackageManager(299): Running dexopt on: com.eilonudi.squrefunc
03-22 19:57:54.766: D/dalvikvm(813): DexOpt: load 383ms, verify+opt 1197ms, 800436 bytes
03-22 19:57:55.036: I/ActivityManager(299): Force stopping package com.eilonudi.squrefunc appid=10046 user=-1
03-22 19:57:55.066: W/PackageManager(299): Code path for pkg : com.eilonudi.squrefunc changing from /data/app/com.eilonudi.squrefunc-2.apk to /data/app/com.eilonudi.squrefunc-1.apk
03-22 19:57:55.066: W/PackageManager(299): Resource path for pkg : com.eilonudi.squrefunc changing from /data/app/com.eilonudi.squrefunc-2.apk to /data/app/com.eilonudi.squrefunc-1.apk
03-22 19:57:55.926: D/dalvikvm(299): GC_CONCURRENT freed 529K, 25% free 5371K/7116K, paused 95ms+21ms, total 295ms
03-22 19:57:55.996: D/PackageManager(299): New package installed in /data/app/com.eilonudi.squrefunc-1.apk
03-22 19:57:56.266: I/ActivityManager(299): Force stopping package com.eilonudi.squrefunc appid=10046 user=0
03-22 19:57:56.566: D/dalvikvm(419): GC_EXPLICIT freed 106K, 16% free 3821K/4504K, paused 9ms+14ms, total 134ms
03-22 19:57:56.756: I/InputReader(299): Reconfiguring input devices. changes=0x00000010
03-22 19:57:56.796: I/ActivityManager(299): Start proc com.android.keychain for broadcast com.android.keychain/.KeyChainBroadcastReceiver: pid=815 uid=1000 gids={41000, 1015, 1028, 3002, 3001, 3003}
03-22 19:57:57.126: E/Trace(815): error opening trace file: No such file or directory (2)
03-22 19:57:57.226: W/ContextImpl(815): Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1352 android.content.ContextWrapper.startService:450 android.content.ContextWrapper.startService:450 com.android.keychain.KeyChainBroadcastReceiver.onReceive:12 android.app.ActivityThread.handleReceiver:2376
03-22 19:57:57.316: W/AccountTypeManager(602): No authenticator found for type=com.android.exchange, ignoring it.
03-22 19:57:57.326: I/AccountTypeManager(602): Loaded meta-data for 0 account types, 0 accounts in 12ms(wall) 6ms(cpu)
03-22 19:57:57.356: D/dalvikvm(453): GC_EXPLICIT freed 263K, 13% free 2708K/3108K, paused 13ms+14ms, total 1060ms
03-22 19:57:57.786: I/InputReader(299): Reconfiguring input devices. changes=0x00000010
03-22 19:57:58.376: W/InputMethodManagerService(299): Found no subtypes in a system IME: com.android.inputmethod.pinyin
03-22 19:57:58.456: W/AccountTypeManager(602): No authenticator found for type=com.android.exchange, ignoring it.
03-22 19:57:58.466: I/AccountTypeManager(602): Loaded meta-data for 0 account types, 0 accounts in 14ms(wall) 7ms(cpu)
03-22 19:57:58.556: I/ActivityManager(299): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=829 uid=10014 gids={50014, 1015, 1028}
03-22 19:57:58.796: D/dalvikvm(37): GC_EXPLICIT freed 38K, 8% free 2369K/2552K, paused 8ms+9ms, total 256ms
03-22 19:57:58.986: D/dalvikvm(37): GC_EXPLICIT freed <1K, 8% free 2369K/2552K, paused 13ms+18ms, total 190ms
03-22 19:57:59.096: E/Trace(829): error opening trace file: No such file or directory (2)
03-22 19:57:59.206: D/dalvikvm(37): GC_EXPLICIT freed <1K, 8% free 2369K/2552K, paused 23ms+19ms, total 217ms
03-22 19:58:00.916: D/dalvikvm(299): GC_EXPLICIT freed 629K, 25% free 5340K/7116K, paused 75ms+102ms, total 1519ms
03-22 19:58:01.216: D/AndroidRuntime(788): Shutting down VM
03-22 19:58:01.296: D/dalvikvm(788): GC_CONCURRENT freed 94K, 18% free 467K/564K, paused 11ms+2ms, total 52ms
03-22 19:58:01.296: D/jdwp(788): Got wake-up signal, bailing out of select
03-22 19:58:01.296: D/dalvikvm(788): Debugger has detached; object registry had 1 entries
03-22 19:58:01.878: I/ActivityManager(299): Start proc com.android.quicksearchbox for broadcast com.android.quicksearchbox/.CorporaUpdateReceiver: pid=848 uid=10001 gids={50001, 3003, 1028}
03-22 19:58:02.596: E/Trace(848): error opening trace file: No such file or directory (2)
03-22 19:58:03.256: D/AndroidRuntime(852): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
03-22 19:58:03.256: D/AndroidRuntime(852): CheckJNI is ON
03-22 19:58:03.436: D/dalvikvm(852): Trying to load lib libjavacore.so 0x0
03-22 19:58:03.487: D/dalvikvm(852): Added shared lib libjavacore.so 0x0
03-22 19:58:03.506: W/RecognitionManagerService(299): no available voice recognition services found for user 0
03-22 19:58:03.616: I/Choreographer(419): Skipped 1174 frames! The application may be doing too much work on its main thread.
03-22 19:58:03.627: D/dalvikvm(852): Trying to load lib libnativehelper.so 0x0
03-22 19:58:03.627: D/dalvikvm(852): Added shared lib libnativehelper.so 0x0
03-22 19:58:03.996: I/Choreographer(419): Skipped 37 frames! The application may be doing too much work on its main thread.
03-22 19:58:05.726: D/AndroidRuntime(852): Calling main entry com.android.commands.am.Am
03-22 19:58:05.746: D/dalvikvm(852): Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
03-22 19:58:05.837: I/ActivityManager(299): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.eilonudi.squrefunc/.MainActivity} from pid 852
03-22 19:58:05.909: D/PermissionCache(36): checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (14464 us)
03-22 19:58:05.926: W/WindowManager(299): Failure taking screenshot for (164x246) to layer 21005
03-22 19:58:06.017: D/AndroidRuntime(852): Shutting down VM
03-22 19:58:06.067: D/dalvikvm(873): Not late-enabling CheckJNI (already on)
03-22 19:58:06.117: I/ActivityManager(299): Start proc com.eilonudi.squrefunc for activity com.eilonudi.squrefunc/.MainActivity: pid=873 uid=10046 gids={50046, 1028}
03-22 19:58:06.117: D/dalvikvm(852): GC_CONCURRENT freed 95K, 17% free 499K/596K, paused 2ms+7ms, total 75ms
03-22 19:58:06.128: D/jdwp(852): Got wake-up signal, bailing out of select
03-22 19:58:06.128: D/dalvikvm(852): Debugger has detached; object registry had 1 entries
03-22 19:58:06.786: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
03-22 19:58:07.046: I/Choreographer(299): Skipped 41 frames! The application may be doing too much work on its main thread.
03-22 19:58:07.156: I/Choreographer(299): Skipped 46 frames! The application may be doing too much work on its main thread.
03-22 19:58:07.366: E/Trace(873): error opening trace file: No such file or directory (2)
03-22 19:58:07.756: I/Choreographer(299): Skipped 34 frames! The application may be doing too much work on its main thread.
03-22 19:58:08.046: I/Choreographer(419): Skipped 76 frames! The application may be doing too much work on its main thread.
03-22 19:58:08.296: I/try(873): start view
03-22 19:58:08.336: D/AndroidRuntime(873): Shutting down VM
03-22 19:58:08.336: W/dalvikvm(873): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-22 19:58:08.376: E/AndroidRuntime(873): FATAL EXCEPTION: main
03-22 19:58:08.376: E/AndroidRuntime(873): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eilonudi.squrefunc/com.eilonudi.squrefunc.MainActivity}: java.lang.NullPointerException
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.os.Looper.loop(Looper.java:137)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-22 19:58:08.376: E/AndroidRuntime(873): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 19:58:08.376: E/AndroidRuntime(873): at java.lang.reflect.Method.invoke(Method.java:511)
03-22 19:58:08.376: E/AndroidRuntime(873): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-22 19:58:08.376: E/AndroidRuntime(873): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-22 19:58:08.376: E/AndroidRuntime(873): at dalvik.system.NativeStart.main(Native Method)
03-22 19:58:08.376: E/AndroidRuntime(873): Caused by: java.lang.NullPointerException
03-22 19:58:08.376: E/AndroidRuntime(873): at com.eilonudi.squrefunc.MainActivity.onCreate(MainActivity.java:69)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.Activity.performCreate(Activity.java:5104)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-22 19:58:08.376: E/AndroidRuntime(873): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-22 19:58:08.376: E/AndroidRuntime(873): ... 11 more
03-22 19:58:08.416: W/ActivityManager(299): Force finishing activity com.eilonudi.squrefunc/.MainActivity
03-22 19:58:08.486: W/WindowManager(299): Failure taking screenshot for (164x246) to layer 21010
03-22 19:58:09.016: W/ActivityManager(299): Activity pause timeout for ActivityRecord{40e98aa0 u0 com.eilonudi.squrefunc/.MainActivity}
03-22 19:58:09.066: I/Choreographer(299): Skipped 156 frames! The application may be doing too much work on its main thread.
03-22 19:58:09.136: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
03-22 19:58:09.526: I/Choreographer(419): Skipped 303 frames! The application may be doing too much work on its main thread.
03-22 19:58:09.727: I/Choreographer(299): Skipped 63 frames! The application may be doing too much work on its main thread.
03-22 19:58:09.826: I/ARMAssembler(36): generated scanline__00000077:03515104_00008001_00000000 [113 ipp] (134 ins) at [0x40eb3460:0x40eb3678] in 2950837 ns
03-22 19:58:09.896: I/Choreographer(299): Skipped 55 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.006: I/Choreographer(299): Skipped 50 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.216: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
03-22 19:58:10.396: I/Choreographer(299): Skipped 46 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.416: I/Choreographer(299): Skipped 58 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.526: I/Choreographer(299): Skipped 47 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.586: I/Choreographer(299): Skipped 37 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.696: I/Choreographer(299): Skipped 72 frames! The application may be doing too much work on its main thread.
03-22 19:58:10.776: I/Choreographer(299): Skipped 30 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.016: I/Choreographer(299): Skipped 36 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.086: I/Choreographer(299): Skipped 36 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.206: I/Choreographer(299): Skipped 66 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.326: D/dalvikvm(299): GC_CONCURRENT freed 208K, 19% free 5785K/7116K, paused 14ms+83ms, total 1881ms
03-22 19:58:11.326: I/Choreographer(299): Skipped 46 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.776: I/Choreographer(299): Skipped 33 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.806: I/Choreographer(299): Skipped 59 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.856: I/Choreographer(299): Skipped 49 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.896: D/dalvikvm(419): GC_FOR_ALLOC freed 201K, 16% free 3815K/4504K, paused 656ms, total 700ms
03-22 19:58:11.958: I/Choreographer(299): Skipped 63 frames! The application may be doing too much work on its main thread.
03-22 19:58:11.996: I/Choreographer(299): Skipped 76 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.059: I/Choreographer(299): Skipped 53 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.086: I/Choreographer(299): Skipped 49 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.156: I/Process(873): Sending signal. PID: 873 SIG: 9
03-22 19:58:12.196: I/ActivityManager(299): Process com.eilonudi.squrefunc (pid 873) has died.
03-22 19:58:12.226: I/Choreographer(299): Skipped 122 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.366: I/Choreographer(299): Skipped 167 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.576: I/Choreographer(299): Skipped 55 frames! The application may be doing too much work on its main thread.
03-22 19:58:12.756: I/Choreographer(299): Skipped 79 frames! The application may be doing too much work on its main thread.
03-22 19:58:13.076: I/Choreographer(299): Skipped 35 frames! The application may be doing too much work on its main thread.
03-22 19:58:13.236: W/InputMethodManagerService(299): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4107b340 attribute=null, token = android.os.BinderProxy#40f8fbc8
03-22 19:58:18.206: D/ExchangeService(691): Received deviceId from Email app: null
03-22 19:58:18.206: D/ExchangeService(691): !!! deviceId unknown; stopping self and retrying

First write your these lines in onCreate method after setContentView.
final EditText tf1 = (EditText)findViewById(R.id.editText1);
final EditText tf2 = (EditText)findViewById(R.id.editText2);
final EditText tf3 = (EditText)findViewById(R.id.editText3);
final TextView result1 = (TextView) findViewById(R.id.textView4);
final TextView result2 = (TextView) findViewById(R.id.textView6);
final Button caculate = (Button) findViewById(R.id.button1);
and Check your AndroidManifest.xml have your entry all correctly.
See these links
Android "No content provider found for permission revoke"
Application not installing in android 4.0 ICS

Related

Sudden app shutdown without doing any activity, throws IllegalStateException onMeasure()

My app always shutdown in random time interval (mostly from few minutes to something like 20 mins). The "App stopped working" messagebox appears. Biggest problem is, I don't do anything in app (like interacting with it), and it just random shutdown by itself. Here's logcat print:
07-15 20:34:16.595 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 141
9K, 44% free 13902K/24391K, paused 4ms+9ms, total 66ms
07-15 20:34:28.997 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1416K, 43% free 13903K/24391K, paused 3ms+7ms, total 56ms
07-15 20:34:29.418 27361-27361/test.game D/AndroidRuntime: Shutting down VM
07-15 20:34:29.418 27361-27361/test.game W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x412b52a0)
07-15 20:34:29.498 27361-27361/test.game E/AndroidRuntime: FATAL EXCEPTION: main java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
at android.view.View.measure(View.java:15293)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
at android.view.View.measure(View.java:15288)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
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:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
One would say, it's because I didn't write setMeasuredDimension() when overriding method onMeasure(). Also, docs say you have to write this line to your onMeasure, otherwise the IllegalStateException will be thrown (see it here).
But I don't overriding onMeasure anywhere in my whole project, so problem is not here (at least not on my side in this case).
Few things to note:
this is full logcat log, and any of these lines ("at android. ...") doesn't link to my code, all goes to source - that means all of these links are gray
this exception always happens only on my S3 Mini (android 4.1.2), but never happened on my old Galaxy Ace S5830i (android 2.3.6) (and yes, I tested it alot - over 20hours on old phone and app still running!).
never happened in emulator
there are no "view resizing" operations running in background, which could cause this exception
I would like to post some code, but I have absolutely no idea where this exception could be thrown.
If someone can help, I'd be really, really grateful. I'm lost at this point...
Since there is not code, this is just a random guess. You can start by looking out for activities in which you've added fragments. It might be that the activity containing a fragment has been destroyed on the device due to inactivity for a long time(and memory requirements by the system, which I think is the reason that you are finding the bug on a device and not on the other). So the case is that the fragment might be referring to a view which might not be attached to the window now. (You can also look for views that use fragment adapters like viewPager, etc if you have used them).

Sudden shutdown with IllegalStateException without doing anything

After 26 minutes leaving my app running without doing anything with it as a user, "app has stopped" window suddenly pop up and Logcat prints only this:
07-15 20:34:16.595 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1419K, 44% free 13902K/24391K, paused 4ms+9ms, total 66ms
07-15 20:34:28.997 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1416K, 43% free 13903K/24391K, paused 3ms+7ms, total 56ms
07-15 20:34:29.418 27361-27361/test.game D/AndroidRuntime: Shutting down VM
07-15 20:34:29.418 27361-27361/test.game W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x412b52a0)
07-15 20:34:29.498 27361-27361/test.game E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
at android.view.View.measure(View.java:15293)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
at android.view.View.measure(View.java:15288)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
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:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Any ideas where could be problem? It happened now for 2nd time (1st time it happened slightly sooner, in about ~13 mins), so it's not some "random" issue.
I can't provide any sample code since none of the Logcat errors links to my code (all goes to the source of specific View). Another strange behaviour is, this happened twice on my S3 Mini (in mentioned 13 and 26 mins), but didn't happened yet on my old Ace S5830i - app is running 4 hours 9 minutes and still nothing here!
edit n1:
Only thing which is running on background is Timer executed each 17ms. I'm displaying hours, minutes, seconds and milis on screen thanks to it.
timer.scheduleAtFixedRate(new TimerTask() ...
currentTime = System.currentTimeMillis() - start;
milisecond = currentTime % 1000;
long x = currentTime / 1000;
second = x % 60;
x /= 60;
minute = x % 60;
x /= 60;
hour = x % 24;
variable start is another System.currentTimeMillis(). It has still value, assigned when this Timer was created.
It's also possible that S3 Mini was a bit "overworked", because I've been developing and testing on it from computer all the day (and the newest Android Studio eats quite a lot memory in phone against AS v1.0.0). I'll try another tests tomorow and let you know how it ended.

App crashes when Home or Back button press

So, my app crashes when I press Home button or Back button. I don't know how to solve this issue. Help!!!
public class Game extends SurfaceView implements SurfaceHolder.Callback {
public Game(Context context) {
super(context);
getHolder().addCallback(this);
gameContext = context;
}
...
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
updateThread.setRunning(false);
while (retry) {
try {updateThread.join();
retry = false; }
catch (InterruptedException e) {
}
}
}
}
And here is a log of process when I press Home button:
07-15 07:43:47.333: I/ActivityManager(285): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 285
07-15 07:43:47.673: W/WindowManager(285): Screenshot failure taking screenshot for (290x515) to layer 21015
07-15 07:43:48.013: D/gralloc(36): Registering a buffer in the process that created it. This may cause memory ordering problems.
07-15 07:43:48.043: I/ARMAssembler(36): generated scanline__00000077:03010104_00008004_00000000 [ 84 ipp] (103 ins) at [0x4296eea0:0x4296f03c] in 599261 ns
07-15 07:43:48.464: D/gralloc(36): Registering a buffer in the process that created it. This may cause memory ordering problems.
07-15 07:43:48.504: I/ActivityManager(285): Config changes=1480 {1.0 310mcc260mnc en_US ldltr sw360dp w360dp h567dp 320dpi nrml port finger -keyb/v/h tball/v s.8}
07-15 07:43:48.574: I/InputReader(285): Reconfiguring input devices. changes=0x00000004
07-15 07:43:48.574: I/InputReader(285): Device reconfigured: id=0, name='qwerty2', size 720x1280, orientation 0, mode 1, display id 0
07-15 07:43:49.003: I/Choreographer(560): Skipped 168 frames! The application may be doing too much work on its main thread.
07-15 07:43:49.343: D/PhoneStatusBar(560): mSettingsPanelGravity = 55
07-15 07:43:49.593: D/dalvikvm(560): GC_FOR_ALLOC freed 7091K, 51% free 7087K/14336K, paused 111ms, total 131ms
07-15 07:43:49.743: W/WindowManager(285): Window freeze timeout expired.
07-15 07:43:49.743: W/WindowManager(285): Force clearing orientation change: Window{41ada620 u0 NavigationBar}
07-15 07:43:49.824: I/WindowManager(285): Screen frozen for +2s101ms due to Window{41ada620 u0 NavigationBar}
07-15 07:43:50.194: I/Choreographer(560): Skipped 124 frames! The application may be doing too much work on its main thread.
07-15 07:43:50.803: I/Choreographer(400): Skipped 119 frames! The application may be doing too much work on its main thread.
07-15 07:43:51.783: I/Choreographer(400): Skipped 106 frames! The application may be doing too much work on its main thread.
07-15 07:43:52.493: I/Choreographer(560): Skipped 194 frames! The application may be doing too much work on its main thread.
07-15 07:43:53.105: W/IInputConnectionWrapper(799): showStatusIcon on inactive InputConnection
07-15 07:43:54.173: D/dalvikvm(285): GC_EXPLICIT freed 3158K, 52% free 5244K/10724K, paused 5ms+11ms, total 134ms
try releasing resources which are consuming memory whenever they are in no use and you can do this in onPause() methods
you can also make some changes in manifiest.xml file like this
<activity android:name="your.package.name.YourActivity" android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" android:screenOrientation="landscape">
...

Unable to make post request in android

I am a very new to android and have followed various tutorials on making a post request in android programming.What i want to do is loging to https://ubresources.com. below is my java class
Results.java
package com.example.fetapp;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Results extends Activity {
private EditText email, pass;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
email = (EditText)findViewById(R.id.email);
pass = (EditText)findViewById(R.id.pass);
Button login = (Button)findViewById(R.id.login);
login.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
postLoginData();
startActivity(new Intent(Results.this, MainPage.class));
}
});
}
public void postLoginData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://ubresources.com/login.json");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", email.getText().toString);
nameValuePairs.add(new BasicNameValuePair("password", pass.getText().toString);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.d("Login", response.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
but still cannot get the response.Please help me out,my logcat info looks is
09-11 17:35:54.244: I/Choreographer(1197): Skipped 73 frames! The application may be doing too much work on its main thread.
09-11 17:35:54.284: D/gralloc_goldfish(1197): Emulator without GPU emulation detected.
09-11 17:35:55.916: I/Choreographer(1197): Skipped 90 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.014: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.114: I/Choreographer(1197): Skipped 46 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.224: I/Choreographer(1197): Skipped 53 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.324: I/Choreographer(1197): Skipped 46 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.434: I/Choreographer(1197): Skipped 42 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.553: I/Choreographer(1197): Skipped 71 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.653: I/Choreographer(1197): Skipped 65 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.763: I/Choreographer(1197): Skipped 52 frames! The application may be doing too much work on its main thread.
09-11 17:35:56.853: I/Choreographer(1197): Skipped 41 frames! The application may be doing too much work on its main thread.
09-11 17:35:57.204: I/Choreographer(1197): Skipped 39 frames! The application may be doing too much work on its main thread.
09-11 17:35:57.474: D/dalvikvm(1197): GC_FOR_ALLOC freed 217K, 5% free 6298K/6599K, paused 63ms, total 66ms
09-11 17:35:57.593: D/dalvikvm(1197): GC_FOR_ALLOC freed 198K, 6% free 6384K/6727K, paused 68ms, total 69ms
09-11 17:35:57.623: I/dalvikvm-heap(1197): Grow heap (frag case) to 7.392MB for 1165616-byte allocation
09-11 17:35:57.773: D/dalvikvm(1197): GC_CONCURRENT freed <1K, 5% free 7522K/7879K, paused 22ms+29ms, total 153ms
09-11 17:35:57.944: D/dalvikvm(1197): GC_FOR_ALLOC freed 0K, 5% free 7523K/7879K, paused 60ms, total 60ms
09-11 17:35:57.953: I/dalvikvm-heap(1197): Grow heap (frag case) to 7.887MB for 519172-byte allocation
09-11 17:35:58.074: D/dalvikvm(1197): GC_CONCURRENT freed 0K, 5% free 8030K/8391K, paused 20ms+9ms, total 120ms
09-11 17:35:58.074: D/dalvikvm(1197): WAIT_FOR_CONCURRENT_GC blocked 32ms
09-11 17:35:58.454: I/Choreographer(1197): Skipped 118 frames! The application may be doing too much work on its main thread.
09-11 17:35:59.164: I/Choreographer(1197): Skipped 193 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.683: I/Choreographer(1197): Skipped 98 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.803: I/Choreographer(1197): Skipped 63 frames! The application may be doing too much work on its main thread.
09-11 17:36:08.953: I/Choreographer(1197): Skipped 74 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.094: I/Choreographer(1197): Skipped 87 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.204: I/Choreographer(1197): Skipped 67 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.324: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:36:09.883: I/Choreographer(1197): Skipped 52 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.004: I/Choreographer(1197): Skipped 56 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.434: I/Choreographer(1197): Skipped 35 frames! The application may be doing too much work on its main thread.
09-11 17:36:10.833: I/Choreographer(1197): Skipped 87 frames! The application may be doing too much work on its main thread.
09-11 17:36:11.573: I/Choreographer(1197): Skipped 154 frames! The application may be doing too much work on its main thread.
09-11 17:36:16.523: I/Choreographer(1197): Skipped 78 frames! The application may be doing too much work on its main thread.
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): KeyEvent: ACTION_UP but key was not down.
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): in android.widget.EditText#4104d088
09-11 17:36:18.643: D/InputEventConsistencyVerifier(1197): 0: sent at 1890932000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=1890932, downTime=1890824, deviceId=0, source=0x101 }
09-11 17:36:30.733: I/Choreographer(1197): Skipped 36 frames! The application may be doing too much work on its main thread.
09-11 17:36:33.234: I/Choreographer(1197): Skipped 47 frames! The application may be doing too much work on its main thread.
09-11 17:36:34.583: D/AndroidRuntime(1197): Shutting down VM
09-11 17:36:34.583: W/dalvikvm(1197): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-11 17:36:34.653: E/AndroidRuntime(1197): FATAL EXCEPTION: main
09-11 17:36:34.653: E/AndroidRuntime(1197): android.os.NetworkOnMainThreadException
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.net.InetAddress.getAllByName(InetAddress.java:214)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-11 17:36:34.653: E/AndroidRuntime(1197): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.example.fetapp.Results.postLoginData(Results.java:61)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.example.fetapp.Results$1.onClick(Results.java:42)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.view.View.performClick(View.java:4084)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.view.View$PerformClick.run(View.java:16966)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Handler.handleCallback(Handler.java:615)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Handler.dispatchMessage(Handler.java:92)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.os.Looper.loop(Looper.java:137)
09-11 17:36:34.653: E/AndroidRuntime(1197): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 17:36:34.653: E/AndroidRuntime(1197): at java.lang.reflect.Method.invoke(Method.java:511)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-11 17:36:34.653: E/AndroidRuntime(1197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-11 17:36:34.653: E/AndroidRuntime(1197): at dalvik.system.NativeStart.main(Native Method)
09-11 17:41:34.804: I/Process(1197): Sending signal. PID: 1197 SIG: 9
09-11 17:41:35.924: E/Trace(1213): error opening trace file: No such file or directory (2)
09-11 17:41:36.934: D/dalvikvm(1213): GC_FOR_ALLOC freed 164K, 5% free 6132K/6407K, paused 87ms, total 91ms
09-11 17:41:37.483: I/Choreographer(1213): Skipped 82 frames! The application may be doing too much work on its main thread.
09-11 17:41:37.523: D/gralloc_goldfish(1213): Emulator without GPU emulation detected.
Try to use Retrofit library for that. It will also parse json for you. You will need only to create simple java object for your data.
Did you included the INTERNET permission on your app?
It seems your error happens either because you don't have Internet access or, less likely, permission to access the Internet.
Try reading Android's help about connecting to see if you didn't forget anything: http://developer.android.com/training/basics/network-ops/connecting.html
And make sure to try this, perhaps you're having the same problem: How to connect android emulator to the internet
The problem can be directly seen in your logcat.
NetworkOnMainThreadException
E/AndroidRuntime(1197): android.os.**NetworkOnMainThreadException** 09-11 17:36:34.653:
Here is a reference to the doc that basically says you can't do this.
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
The DefaultHttpClient is a rather low level class and as such tends to be much harder to use than say something like Retrofit
http://square.github.io/retrofit
Retrofit needs to be downloaded, and does take a little bit of setup, but in the long run you will be much happier using a much more highlevel api for Rest api calls.
Here is another good resource you might be interested in as well. It describes (or at least points you in the direction) of combining Squares's Retrofit and Otto (event bus) into a very nice way to communicate with a Restful web service
http://www.mdswanson.com/blog/2014/04/07/durable-android-rest-clients.html
Your problem there is you didn't implement AsyncTask when retrieving the response or maybe you did not add the permissions for internet / networking?
Try the android volley, it is the one recommended to use as it is owned by google as well as provides you faster networking access. If you try the android volley I can help you in many ways just reach me through my email or twitter. Cheers!

Android App, "source not found" debug error - tried downloading Android Source Code

I'm getting an error in my Android app that says "source not found" and crashes the program. I've already read a number of posts saying that the solution is to download the android source code and load that up in Eclipse, but I tried to no avail.
Here is a bunch of information that may help with my problem, let me know if you need more!
Stack:
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThrea d$ActivityRecord, Intent) line: 2663
ActivityThread.handleLaunchActivity(ActivityThread $ActivityRecord, Intent) line: 2679
ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
ActivityThread$H.handleMessage(Message) line: 2033
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
Is it weird that the first entry is 'ActivityThrea d' with the 'd' cut off? If this is the problem, what went wrong and how do I fix it?
The line of code the debug stops on:
public void AddAnimationID(String index, Integer view)
{
animations.put(index, view);
}
'animations' is a Dictionary and is a member of class Alien. I am calling it like:
Alien alien;
alien.AddAnimationID("idle", R.drawable.idle);
I am correct in thinking that R.drawable.idle is an int right? findViewByID takes an int for the argument...
Here is the logcat, I tried to pinpoint where in the log it started the application, sorry if its too much.
I/ActivityManager( 59): Displayed activity com.android.launcher/com.android.la
uncher2.Launcher: 21357 ms (total 21357 ms)
I/Launcher.Model( 118): not binding apps: no Launcher activity
D/dalvikvm( 118): GC_EXPLICIT freed 5222 objects / 297520 bytes in 114ms
D/dalvikvm( 118): GC_EXPLICIT freed 11360 objects / 562112 bytes in 94ms
D/PackageParser( 59): Scanning package: /data/app/vmdl45576.tmp
I/PackageParser( 59): Game.Main: compat added android.permission.WRITE_EXTERNA
L_STORAGE android.permission.READ_PHONE_STATE
I/PackageManager( 59): Removing non-system package:Game.Main
I/ActivityManager( 59): Force stopping package Game.Main uid=10032
D/dalvikvm( 118): GC_EXTERNAL_ALLOC freed 319 objects / 18064 bytes in 73ms
D/dalvikvm( 59): GC_FOR_MALLOC freed 6857 objects / 349752 bytes in 400ms
D/PackageManager( 59): Scanning package Game.Main
I/PackageManager( 59): Package Game.Main codePath changed from /data/app/Game.
Main-2.apk to /data/app/Game.Main-1.apk; Retaining data and using new
I/PackageManager( 59): /data/app/Game.Main-1.apk changed; unpacking
D/installd( 34): DexInv: --- BEGIN '/data/app/Game.Main-1.apk' ---
I/ActivityManager( 59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=Game.Main/.Main }
D/dalvikvm( 258): DexOpt: load 116ms, verify 200ms, opt 2ms
D/installd( 34): DexInv: --- END '/data/app/Game.Main-1.apk' (success) ---
W/PackageManager( 59): Code path for pkg : Game.Main changing from /data/app/G
ame.Main-2.apk to /data/app/Game.Main-1.apk
W/PackageManager( 59): Resource path for pkg : Game.Main changing from /data/a
pp/Game.Main-2.apk to /data/app/Game.Main-1.apk
D/PackageManager( 59): Activities: Game.Main.Main
I/ActivityManager( 59): Force stopping package Game.Main uid=10032
E/Launcher( 118): Unable to launch. tag=ApplicationInfo(title=Alien Game) inten
t=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
flg=0x10200000 cmp=Game.Main/.Main }
E/Launcher( 118): android.content.ActivityNotFoundException: Unable to find exp
licit activity class {Game.Main/Game.Main.Main}; have you declared this activity
in your AndroidManifest.xml?
E/Launcher( 118): at android.app.Instrumentation.checkStartActivityResult(
Instrumentation.java:1404)
E/Launcher( 118): at android.app.Instrumentation.execStartActivity(Instrum
entation.java:1378)
E/Launcher( 118): at android.app.Activity.startActivityForResult(Activity.
java:2817)
E/Launcher( 118): at com.android.launcher2.Launcher.startActivityForResult
(Launcher.java:1053)
E/Launcher( 118): at android.app.Activity.startActivity(Activity.java:2923
)
E/Launcher( 118): at com.android.launcher2.Launcher.startActivitySafely(La
uncher.java:1462)
E/Launcher( 118): at com.android.launcher2.AllApps2D.onItemClick(AllApps2D
.java:178)
E/Launcher( 118): at android.widget.AdapterView.performItemClick(AdapterVi
ew.java:284)
E/Launcher( 118): at android.widget.AbsListView$PerformClick.run(AbsListVi
ew.java:1696)
E/Launcher( 118): at android.os.Handler.handleCallback(Handler.java:587)
E/Launcher( 118): at android.os.Handler.dispatchMessage(Handler.java:92)
E/Launcher( 118): at android.os.Looper.loop(Looper.java:123)
E/Launcher( 118): at android.app.ActivityThread.main(ActivityThread.java:4
627)
E/Launcher( 118): at java.lang.reflect.Method.invokeNative(Native Method)
E/Launcher( 118): at java.lang.reflect.Method.invoke(Method.java:521)
E/Launcher( 118): at com.android.internal.os.ZygoteInit$MethodAndArgsCalle
r.run(ZygoteInit.java:868)
E/Launcher( 118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.ja
va:626)
E/Launcher( 118): at dalvik.system.NativeStart.main(Native Method)
I/installd( 34): move /data/dalvik-cache/data#app#Game.Main-1.apk#classes.dex
-> /data/dalvik-cache/data#app#Game.Main-1.apk#classes.dex
D/PackageManager( 59): New package installed in /data/app/Game.Main-1.apk
I/ActivityManager( 59): Force stopping package Game.Main uid=10032
I/ActivityManager( 59): Start proc com.svox.pico for broadcast com.svox.pico/.
VoiceDataInstallerReceiver: pid=259 uid=10028 gids={}
D/dalvikvm( 157): GC_EXPLICIT freed 4079 objects / 247824 bytes in 605ms
D/dalvikvm( 59): GC_EXPLICIT freed 6136 objects / 382312 bytes in 493ms
W/RecognitionManagerService( 59): no available voice recognition services foun
d
I/installd( 34): unlink /data/dalvik-cache/data#app#Game.Main-2.apk#classes.de
x
D/AndroidRuntime( 191): Shutting down VM
D/jdwp ( 191): adbd disconnected
I/AndroidRuntime( 191): NOTE: attach of thread 'Binder Thread #3' failed
I/ActivityThread( 259): Publishing provider com.svox.pico.providers.SettingsPro
vider: com.svox.pico.providers.SettingsProvider
D/AndroidRuntime( 269):
D/AndroidRuntime( 269): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime( 269): CheckJNI is ON
D/AndroidRuntime( 269): --- registering native functions ---
I/ActivityManager( 59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=Game.Main/.Main }
I/ActivityManager( 59): Start proc Game.Main for activity Game.Main/.Main: pid
=273 uid=10032 gids={1015}
I/ARMAssembler( 59): generated scanline__00000077:03545404_00000004_00000000 [
47 ipp] (67 ins) at [0x322b68:0x322c74] in 4370882 ns
W/Game.Main.Main( 273): SIS is null
D/AndroidRuntime( 273): Shutting down VM
W/dalvikvm( 273): threadid=1: thread exiting with uncaught exception (group=0x4
001d800)
E/AndroidRuntime( 273): FATAL EXCEPTION: main
E/AndroidRuntime( 273): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{Game.Main/Game.Main.Main}: java.lang.NullPointerException
E/AndroidRuntime( 273): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2663)
E/AndroidRuntime( 273): at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2679)
E/AndroidRuntime( 273): at android.app.ActivityThread.access$2300(Activi
tyThread.java:125)
E/AndroidRuntime( 273): at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:2033)
E/AndroidRuntime( 273): at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime( 273): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 273): at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime( 273): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 273): at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime( 273): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 273): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime( 273): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 273): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 273): at Game.Main.Main.onCreate(Main.java:81)
E/AndroidRuntime( 273): at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1047)
E/AndroidRuntime( 273): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2627)
E/AndroidRuntime( 273): ... 11 more
W/ActivityManager( 59): Force finishing activity Game.Main/.Main
I/ActivityManager( 59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=Game.Main/.Main }
D/AndroidRuntime( 269): Shutting down VM
D/jdwp ( 269): adbd disconnected
I/AndroidRuntime( 269): NOTE: attach of thread 'Binder Thread #3' failed
W/ActivityManager( 59): Activity pause timeout for HistoryRecord{43ed84f8 Game
.Main/.Main}
I/ARMAssembler( 59): generated scanline__00000077:03515104_00000000_00000000 [
33 ipp] (47 ins) at [0x305640:0x3056fc] in 1148283 ns
W/ActivityManager( 59): Launch timeout has expired, giving up wake lock!
Here is the class Alien:
package Game.Main;
import java.util.Dictionary;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
public class Alien
{
private AlienState state;
private Dictionary<String, Integer> animations;
private ImageView imageView;
public Alien()
{
}
public void AddAnimationID(String index, Integer view)
{
animations.put(index, view);
}
public Integer GetAnimationID(String index)
{
return animations.get(index);
}
public void SetImageView(ImageView view)
{
imageView = view;
if(animations.get("idle") != null)
{
imageView.setBackgroundResource(R.drawable.idle);
state = AlienState.idle;
}
}
public ImageView GetImageView()
{
return imageView;
}
public void ChangeView(String index)
{
if(animations.get(index) != null)
{
imageView.setBackgroundResource(animations.get(index));
state = AlienState.valueOf(index);
}
}
}
Here is the onCreate function that this is called from and related information:
package Game.Main;
import java.util.ArrayList;
import java.util.List;
import Game.Main.MainView.MainThread;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class Main extends Activity implements OnClickListener {
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ArrayList<String> dictionary;
private TextView txtText;
private MainThread thread;
private MainView view;
private AnimationDrawable anim;
private Alien alien;
#Override // called when Main is created.
public void onCreate(Bundle savedInstanceState) {
// reload from previous instance
super.onCreate(savedInstanceState);
// set default content view
setContentView(R.layout.main);
view = (MainView)findViewById(R.id.mainView);
thread = view.GetThread();
if (savedInstanceState == null) {
// we were just launched: set up a new game
thread.SetState(GameState.Active);
Log.w(this.getClass().getName(), "SIS is null");
} else {
// we are being restored: resume a previous game
thread.RestoreState(savedInstanceState);
Log.w(this.getClass().getName(), "SIS is nonnull");
}
// setup speak button
Button speakButton = (Button)findViewById(R.id.btn_speak);
// setup text box
txtText = (TextView)findViewById(R.id.txt_text);
// setup our dictionary
dictionary = new ArrayList<String>();
dictionary.add("sit");
dictionary.add("eat");
dictionary.add("jump");
dictionary.add("think");
alien.AddAnimationID("idle", R.drawable.idle);
alien.AddAnimationID("eat", R.drawable.eat);
alien.AddAnimationID("jump", R.drawable.jump);
alien.AddAnimationID("think", R.drawable.think);
alien.AddAnimationID("run", R.drawable.run);
alien.AddAnimationID("sit", R.drawable.sit);
alien.SetImageView((ImageView)findViewById(R.id.alien_image));
// check to see if a recognition activity is present
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
// if activities were found, cancel speech recognition
if (activities.size() != 0)
speakButton.setOnClickListener(this);
else
{
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
}
I am using Eclipse on Windows 7 x64. I have all of the newest updates to the android SDK and I downloaded the android source code and added it to the Eclipse patch because previous posts led me to try that. The code breaks for debug when the first time AddAnimationID is called. I hope this is all you need, thanks! Sorry if I'm doing this wrong by the way, I'm somewhat new at this.
Edit: Looks like I didn't have enough breakpoints, the culprit is not the AddAnimationID function but actually the SetImageView one. The if statement seems to not work, so I've commented it out for now. I'll post back once I've figured it out. It's probably something silly that works in another language but not Java...
The problem ended up being the Dictionary class, I got it to vaguely work by throwing in a bunch of try/catch blocks, but that wasn't what I wanted, so I replaced it with a Map and it works fine.
To append some useful information I've found since then to this answer, as a decent number of people have visited this page: Eclipse will say "Source not found" for nearly every random error you make in your app. Here are some steps to follow in order to locate these troublesome lines of code:
1) Step through your code line-by-line (using step filters to ignore code that you did not write) until you find the offending line, this is most likely where you made your mistake. If the error is deep in the code, place a break point close to, but not after, where you feel the issue occurs and step from there.
2) Uncaught exceptions and other useful information can sometimes be found in the Variables panel.
3) "Source Not Found" just means the line of code that generated the exception is in a binary file. It does exist, Eclipse just can't show it to you.
I had the same problem in my project that has reference to a library project. The cause of problem was an activity that existed in library project and I forgot mention it in my project manifest.xml file.

Categories

Resources