I can't show alert dialog. Everything is right until I set the method dialog.show(), then I can't open my application. Without this method everything is fine.
I declared two global objects:
AlertDialog.Builder builder;
AlertDialog dialog;
Then in MainActivity, I build a dialog by builder and create it.
builder = new AlertDialog.Builder(this.getApplicationContext());
builder.setMessage("We're sorry, but on Your device accelerometer isn't available")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which)
{
MainActivity.this.finish();
}
});
dialog = builder.create();
To this moment everything works and there's no any exceptions, but when I want to show the dialog, some exceptions appear and I can't run this application:
dialog.show(); //this method doesn't work and causes problems
What did I do wrong?
EDIT:
Exceptions:
06-26 20:49:03.540: D/dalvikvm(4085): GC_FOR_ALLOC freed 38K, 8% free 2499K/2712K, paused 42ms, total 45ms
06-26 20:49:03.580: I/dalvikvm-heap(4085): Grow heap (frag case) to 6.146MB for 3712016-byte allocation
06-26 20:49:03.700: D/dalvikvm(4085): GC_FOR_ALLOC freed 2K, 4% free 6121K/6340K, paused 112ms, total 112ms
06-26 20:49:03.770: D/dalvikvm(4085): GC_CONCURRENT freed <1K, 4% free 6121K/6340K, paused 6ms+16ms, total 71ms
06-26 20:49:04.460: D/gralloc_goldfish(4085): Emulator without GPU emulation detected.
06-26 20:49:42.030: E/Trace(4138): error opening trace file: No such file or directory (2)
06-26 20:49:42.900: D/dalvikvm(4138): GC_FOR_ALLOC freed 41K, 8% free 2499K/2716K, paused 66ms, total 68ms
06-26 20:49:42.940: I/dalvikvm-heap(4138): Grow heap (frag case) to 6.146MB for 3712016-byte allocation
06-26 20:49:43.050: D/dalvikvm(4138): GC_FOR_ALLOC freed 2K, 4% free 6121K/6344K, paused 107ms, total 107ms
06-26 20:49:43.120: D/dalvikvm(4138): GC_CONCURRENT freed <1K, 4% free 6121K/6344K, paused 5ms+5ms, total 70ms
06-26 20:49:43.540: D/dalvikvm(4138): GC_FOR_ALLOC freed 3638K, 53% free 3483K/7300K, paused 36ms, total 37ms
06-26 20:49:43.621: D/AndroidRuntime(4138): Shutting down VM
06-26 20:49:43.630: W/dalvikvm(4138): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-26 20:49:43.640: E/AndroidRuntime(4138): FATAL EXCEPTION: main
06-26 20:49:43.640: E/AndroidRuntime(4138): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.accelerometertest/com.example.accelerometertest.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.os.Looper.loop(Looper.java:137)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-26 20:49:43.640: E/AndroidRuntime(4138): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 20:49:43.640: E/AndroidRuntime(4138): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-26 20:49:43.640: E/AndroidRuntime(4138): at dalvik.system.NativeStart.main(Native Method)
06-26 20:49:43.640: E/AndroidRuntime(4138): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Dialog.show(Dialog.java:281)
06-26 20:49:43.640: E/AndroidRuntime(4138): at com.example.accelerometertest.MainActivity.onCreate(MainActivity.java:67)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Activity.performCreate(Activity.java:5104)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-26 20:49:43.640: E/AndroidRuntime(4138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-26 20:49:43.640: E/AndroidRuntime(4138): ... 11 more
change
builder = new AlertDialog.Builder(this.getApplicationContext());
to (As long as thisis your MainActivity )
builder = new AlertDialog.Builder(this);
Related
Thank you guys! The reason is somewhere simpler than I think. I feel something futility.. :
-)
I have already added activity names on androidmanifest.xml.
My code is simple.
Intent intent=new Intent(MainActivity.this, AddAddressActivity.class);
intent.putExtra("respond", responsebody);
intent.putExtra("userid", txtID.getText().toString());
intent.putExtra("password", txtPW.getText().toString());
MainActivity.this.startActivity(intent);
just this.
Why are crashes caused in this code? I can't find on it.
But the more stranger thing is that crash aren't caused when I make AddAddressActivity like basic templete(source when it is made at first).
Then, is AddAddressActivity a problem?
Thanks to read my question. You could misunderstand it because of my short english. If you have something hard to understand, please ask me on comment.
Here is Logcat. I can't find reason in this text..
02-28 02:42:53.876: D/dalvikvm(6195): GC_FOR_ALLOC freed 122K, 19% free 9983K/12192K, paused 17ms, total 17ms
02-28 02:42:53.886: I/dalvikvm-heap(6195): Grow heap (frag case) to 15.536MB for 3936016-byte allocation
02-28 02:42:53.901: D/dalvikvm(6195): GC_FOR_ALLOC freed <1K, 14% free 13826K/16036K, paused 13ms, total 13ms
02-28 02:42:54.011: D/dalvikvm(6195): GC_FOR_ALLOC freed <1K, 14% free 13826K/16036K, paused 9ms, total 9ms
02-28 02:42:54.031: I/dalvikvm-heap(6195): Grow heap (frag case) to 30.549MB for 15744016-byte allocation
02-28 02:42:54.041: D/dalvikvm(6195): GC_FOR_ALLOC freed 0K, 8% free 29201K/31412K, paused 11ms, total 11ms
02-28 02:42:54.201: D/libEGL(6195): loaded /system/lib/egl/libEGL_mali.so
02-28 02:42:54.201: D/libEGL(6195): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-28 02:42:54.206: D/libEGL(6195): loaded /system/lib/egl/libGLESv2_mali.so
02-28 02:42:54.211: E/(6195): Device driver API match
02-28 02:42:54.211: E/(6195): Device driver API version: 23
02-28 02:42:54.211: E/(6195): User space API version: 23
02-28 02:42:54.211: E/(6195): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct 30 09:36:10 KST 2013
02-28 02:42:54.276: D/OpenGLRenderer(6195): Enabling debug mode 0
02-28 02:43:02.696: I/webclipboard(6195): clipservice: android.sec.clipboard.ClipboardExManager#4419e048
02-28 02:43:02.711: D/AndroidRuntime(6195): Shutting down VM
02-28 02:43:02.711: W/dalvikvm(6195): threadid=1: thread exiting with uncaught exception (group=0x420ac700)
02-28 02:43:02.721: E/AndroidRuntime(6195): FATAL EXCEPTION: main
02-28 02:43:02.721: E/AndroidRuntime(6195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mcdelivery/com.example.mcdelivery.AddAddressActivity}: java.lang.NullPointerException
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.access$700(ActivityThread.java:168)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.os.Looper.loop(Looper.java:137)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.main(ActivityThread.java:5493)
02-28 02:43:02.721: E/AndroidRuntime(6195): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 02:43:02.721: E/AndroidRuntime(6195): at java.lang.reflect.Method.invoke(Method.java:525)
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
02-28 02:43:02.721: E/AndroidRuntime(6195): at dalvik.system.NativeStart.main(Native Method)
02-28 02:43:02.721: E/AndroidRuntime(6195): Caused by: java.lang.NullPointerException
02-28 02:43:02.721: E/AndroidRuntime(6195): at com.example.mcdelivery.AddAddressActivity.onCreate(AddAddressActivity.java:18)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.Activity.performCreate(Activity.java:5372)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-28 02:43:02.721: E/AndroidRuntime(6195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
02-28 02:43:02.721: E/AndroidRuntime(6195): ... 11 more
02-28 02:43:02.751: V/webkit(6195): BrowserFrame constructor: this=Handler (android.webkit.BrowserFrame) {4419b1f0}
AddAddressActivity.java
package com.example.mcdelivery;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
public class AddAddressActivity extends Activity {
WebView webview;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addaddress);
Intent intent=new Intent(this.getIntent());
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
}
}
webView gives a NPE on this line
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
Because you haven't yet initialized it. You only declare it
WebView webview;
Somewhere (before that line and after setContentView()) you need to initialize it
You have only declared WebView not initialized it
setContentView(R.layout.activity_addaddress);
webview =(WebView)findViewById(R.id.webView); //missing
Intent intent= getIntent();
webview.loadUrl("https://www.mcdelivery.co.kr/kr/jsp/sys/customerLogin.do?userName=" + intent.getStringExtra("username") + "&password=" + intent.getStringExtra("password") + "&imgLogin.x=0&imgLogin.y=0");
I think that's from a bad handling of the Context belonging to your app.
Replace
Intent intent=new Intent(MainActivity.this, AddAddressActivity.class);
with
Intent intent=new Intent(this, AddAddressActivity.class); .
My Android application crashes in the emulator with, with the following being output to the logs:
09-26 14:04:02.123: D/dalvikvm(716): GC_FOR_ALLOC freed 66K, 6% free 2675K/2844K, paused 29ms, total 30ms
09-26 14:04:02.123: I/dalvikvm-heap(716): Grow heap (frag case) to 3.455MB for 782224-byte allocation
09-26 14:04:02.173: D/dalvikvm(716): GC_FOR_ALLOC freed 2K, 5% free 3437K/3608K, paused 42ms, total 42ms
09-26 14:04:02.303: D/dalvikvm(716): GC_FOR_ALLOC freed <1K, 5% free 3436K/3608K, paused 38ms, total 39ms
09-26 14:04:02.314: I/dalvikvm-heap(716): Grow heap (frag case) to 4.778MB for 1389712-byte allocation
09-26 14:04:02.363: D/dalvikvm(716): GC_FOR_ALLOC freed <1K, 4% free 4793K/4968K, paused 52ms, total 52ms
09-26 14:04:02.423: D/AndroidRuntime(716): Shutting down VM
09-26 14:04:02.423: W/dalvikvm(716): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
09-26 14:04:02.433: E/AndroidRuntime(716): FATAL EXCEPTION: main
09-26 14:04:02.433: E/AndroidRuntime(716): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sample_proj/com.example.sample_proj.MainActivity}: java.lang.NullPointerException
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.os.Looper.loop(Looper.java:137)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-26 14:04:02.433: E/AndroidRuntime(716): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 14:04:02.433: E/AndroidRuntime(716): at java.lang.reflect.Method.invoke(Method.java:525)
09-26 14:04:02.433: E/AndroidRuntime(716): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-26 14:04:02.433: E/AndroidRuntime(716): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 14:04:02.433: E/AndroidRuntime(716): at dalvik.system.NativeStart.main(Native Method)
09-26 14:04:02.433: E/AndroidRuntime(716): Caused by: java.lang.NullPointerException
09-26 14:04:02.433: E/AndroidRuntime(716): at com.example.sample_proj.MainActivity.onCreate(MainActivity.java:21)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.Activity.performCreate(Activity.java:5133)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-26 14:04:02.433: E/AndroidRuntime(716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-26 14:04:02.433: E/AndroidRuntime(716): ... 11 more
Would someone please help me in understanding why NullPointerException is being thrown and how I can resolve it?
Check this line in your MainActivity
MainActivity.java:21
You have probably used findviewbyid and the following happened
you forgot to put the line "setContentView" or put it after findviewbyid
or you put the contentView to the wrong layout
1 and 2 are not it, and you did findviewbyid to non existing id in the given layout- and tried to use that object aterwards, because the id is incorrect, the object returns null, and you are trying to use it
I am a beginner in android development and i tried to make a small app. it was working fine but, then i started fiddling with the AndroidManifest file, but anyway i had to restore it from the backup i already created.
But now the app starts but just to show the first activity, and then it says "UNFORTUNATELY, APP TITLE HAS STOPPED".
I have tried the following:
1. Trying to find error in AndroidMainfest.
2. Project->Clean
3. Searching stackoverflow
But nothing seems to work
This is my console
[2013-06-28 12:18:07 - start] Uploading start.apk onto device 'emulator-5554'
[2013-06-28 12:18:08 - start] Installing start.apk...
[2013-06-28 12:18:14 - start] Success!
[2013-06-28 12:18:14 - start] Failed to install start.apk on device 'emulator-5554': device not found
[2013-06-28 12:18:14 - start] com.android.ddmlib.InstallException: device not found
[2013-06-28 12:18:14 - start] Launch canceled!
and my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.start"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:configChanges="orientation|keyboardHidden|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingPointActivity"
android:configChanges="orientation|keyboardHidden|screenSize" >
<intent-filter>
<action android:name="com.davinci.STARTINGPOINTACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:configChanges="orientation|keyboardHidden|screenSize" >
<intent-filter>
<action android:name="com.davinci.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
my logcat output
06-26 20:36:41.007: D/dalvikvm(2673): Not late-enabling CheckJNI (already on)
06-26 20:36:41.567: E/Trace(2673): error opening trace file: No such file or directory (2)
06-26 20:36:42.377: D/dalvikvm(2673): GC_FOR_ALLOC freed 58K, 7% free 2497K/2676K, paused 29ms, total 33ms
06-26 20:36:42.377: I/dalvikvm-heap(2673): Grow heap (frag case) to 3.563MB for 1058416-byte allocation
06-26 20:36:42.507: D/dalvikvm(2673): GC_FOR_ALLOC freed 2K, 5% free 3528K/3712K, paused 123ms, total 123ms
06-26 20:36:42.797: D/dalvikvm(2673): GC_CONCURRENT freed 1K, 5% free 3528K/3712K, paused 6ms+32ms, total 290ms
06-26 20:36:43.317: D/gralloc_goldfish(2673): Emulator without GPU emulation detected.
06-26 20:36:45.407: D/dalvikvm(2673): GC_FOR_ALLOC freed 13K, 4% free 3637K/3772K, paused 32ms, total 38ms
06-26 20:36:45.407: I/dalvikvm-heap(2673): Grow heap (frag case) to 4.274MB for 635812-byte allocation
06-26 20:36:45.487: D/dalvikvm(2673): GC_CONCURRENT freed 3K, 4% free 4255K/4396K, paused 4ms+3ms, total 72ms
06-26 20:36:45.487: D/dalvikvm(2673): WAIT_FOR_CONCURRENT_GC blocked 16ms
06-26 20:36:45.777: E/ArrayAdapter(2673): You must supply a resource ID for a TextView
06-26 20:36:45.777: D/AndroidRuntime(2673): Shutting down VM
06-26 20:36:45.787: W/dalvikvm(2673): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-26 20:36:45.927: E/AndroidRuntime(2673): FATAL EXCEPTION: main
06-26 20:36:45.927: E/AndroidRuntime(2673): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ListView.makeAndAddView(ListView.java:1831)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ListView.fillDown(ListView.java:674)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ListView.fillFromTop(ListView.java:735)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ListView.layoutChildren(ListView.java:1652)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.AbsListView.onLayout(AbsListView.java:1994)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.View.layout(View.java:14008)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.View.layout(View.java:14008)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.View.layout(View.java:14008)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.View.layout(View.java:14008)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.Choreographer.doFrame(Choreographer.java:532)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.os.Handler.handleCallback(Handler.java:725)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.os.Handler.dispatchMessage(Handler.java:92)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.os.Looper.loop(Looper.java:137)
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-26 20:36:45.927: E/AndroidRuntime(2673): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 20:36:45.927: E/AndroidRuntime(2673): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 20:36:45.927: E/AndroidRuntime(2673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-26 20:36:45.927: E/AndroidRuntime(2673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-26 20:36:45.927: E/AndroidRuntime(2673): at dalvik.system.NativeStart.main(Native Method)
06-26 20:36:45.927: E/AndroidRuntime(2673): Caused by: java.lang.ClassCastException: android.widget.TwoLineListItem cannot be cast to android.widget.TextView
06-26 20:36:45.927: E/AndroidRuntime(2673): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
06-26 20:36:45.927: E/AndroidRuntime(2673): ... 37 more
and splash.java
package com.example.start;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer song;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
song = MediaPlayer.create(Splash.this,R.raw.chimesound);
song.start();
Thread timer = new Thread()
{
public void run(){
try{
sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStatingPointActivity = new Intent("com.davinci.MENU");
startActivity(openStatingPointActivity);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
song.release();
finish();
}
}
menu.java
package com.example.start;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
String Classes[]= {"Ëxample1","StartingPointActivity","example1","example2","example3"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_2, Classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String activityName = Classes[position];
try
{
Class ourClass = Class.forName("com.example.start." + activityName);
Intent ourIntent = new Intent(Menu.this,ourClass);
startActivity(ourIntent);
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
}
}
Please HELP !
try installing your apk by command prompt. Open cmd and write
adb install start.apk
which is in your bin folder of your project.
Don't forget to go bin directory before this command.i.e.
cd C:/path/to/your/bin
I'm currently try to run some opencv filters (i.e find egde, Median, ...) on images which are stored in the image gallery folder.
But I get error for loading image. My device is galaxy tab 10.1 with android 3.2, my opencv - API level 8.
I have the following source on a Button:
#Override
public void onClick(View v) {
Bitmap myBitmap = BitmapFactory.decodeFile("/sdcard/image1.jpg");
Bitmap myBitmap32 = myBitmap.copy(Bitmap.Config.ARGB_8888, true);
Mat pic1 = Utils.bitmapToMat(myBitmap32);
}
Here is LogCat:
02-07 12:31:27.290: I/System.out(16522): Not a DRM File, opening notmally
02-07 12:31:27.290: I/System.out(16522): buffer returned
02-07 12:31:27.310: D/dalvikvm(16522): GC_FOR_ALLOC freed 11K, 21% free 6975K/8775K, paused 19ms
02-07 12:31:27.320: I/dalvikvm-heap(16522): Grow heap (frag case) to 12.918MB for 6291472-byte allocation
02-07 12:31:27.340: D/dalvikvm(16522): GC_FOR_ALLOC freed <1K, 13% free 13119K/14983K, paused 19ms
02-07 12:31:27.380: D/dalvikvm(16522): GC_CONCURRENT freed 0K, 13% free 13119K/14983K, paused 2ms+2ms
02-07 12:31:27.710: D/dalvikvm(16522): GC_FOR_ALLOC freed 55K, 13% free 13063K/14983K, paused 20ms
02-07 12:31:27.730: I/dalvikvm-heap(16522): Grow heap (frag case) to 24.864MB for 12582928-byte allocation
02-07 12:31:27.780: D/dalvikvm(16522): GC_FOR_ALLOC freed 0K, 8% free 25351K/27335K, paused 21ms
02-07 12:31:27.830: D/dalvikvm(16522): GC_CONCURRENT freed <1K, 8% free 25351K/27335K, paused 2ms+3ms
02-07 12:31:27.890: W/dalvikvm(16522): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/android/Utils;
02-07 12:31:27.890: D/AndroidRuntime(16522): Shutting down VM
02-07 12:31:27.890: W/dalvikvm(16522): threadid=1: thread exiting with uncaught exception (group=0x400fc760)
02-07 12:31:27.890: E/AndroidRuntime(16522): FATAL EXCEPTION: main
02-07 12:31:27.890: E/AndroidRuntime(16522): java.lang.ExceptionInInitializerError
02-07 12:31:27.890: E/AndroidRuntime(16522): at photo.klu.PhotoKLUActivity$1.onClick(PhotoKLUActivity.java:82)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.view.View.performClick(View.java:3127)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.view.View$PerformClick.run(View.java:12025)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Handler.handleCallback(Handler.java:587)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.os.Looper.loop(Looper.java:132)
02-07 12:31:27.890: E/AndroidRuntime(16522): at android.app.ActivityThread.main(ActivityThread.java:4126)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.reflect.Method.invoke(Method.java:491)
02-07 12:31:27.890: E/AndroidRuntime(16522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
02-07 12:31:27.890: E/AndroidRuntime(16522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
02-07 12:31:27.890: E/AndroidRuntime(16522): at dalvik.system.NativeStart.main(Native Method)
02-07 12:31:27.890: E/AndroidRuntime(16522): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.Runtime.loadLibrary(Runtime.java:425)
02-07 12:31:27.890: E/AndroidRuntime(16522): at java.lang.System.loadLibrary(System.java:554)
02-07 12:31:27.890: E/AndroidRuntime(16522): at org.opencv.android.Utils.<clinit>(Utils.java:86)
02-07 12:31:27.890: E/AndroidRuntime(16522): ... 12 more
02-07 12:31:30.010: I/dalvikvm(16522): threadid=4: reacting to signal 3
02-07 12:31:30.010: I/dalvikvm(16522): Wrote stack traces to '/data/anr/traces.txt'
02-07 12:31:37.470: I/Process(16522): Sending signal. PID: 16522 SIG: 9
Any ideas?
Thank you.
The openCV library is not attached to your application. Please do the following (i assume that the openCV library is imported to your workspace). On Package Explorer > Right click on the application project > properties > under Library click Add > select openCV Be sure that on Java Build Path you don't have anything related to openCV
I'm designing an application that allows the user to retrieve his data from the server, I'm furnishing this using two different activities, the first one receives the username as a text input and the second one displays the user's data based on the username. I'm using JSON schema for storing and retrieving the data. The app works fine for the first time but when I logout from the second screen using finish() and try to re-enter a new username in the first screen "the app force closes". This has been giving me sleepless nights, want to be overwhelmed with your support.
12-04 16:28:35.289: D/dalvikvm(553): GC_FOR_ALLOC freed 64K, 4% free 6893K/7171K, paused 64ms
12-04 16:28:35.299: I/dalvikvm-heap(553): Grow heap (frag case) to 7.757MB for 1000016-byte allocation
12-04 16:28:35.399: D/dalvikvm(553): GC_CONCURRENT freed 1K, 5% free 7868K/8199K, paused 16ms+3ms
12-04 16:28:35.529: D/dalvikvm(553): GC_FOR_ALLOC freed <1K, 5% free 7869K/8199K, paused 31ms
12-04 16:28:35.539: I/dalvikvm-heap(553): Grow heap (frag case) to 8.180MB for 443572-byte allocation
12-04 16:28:35.589: D/dalvikvm(553): GC_CONCURRENT freed 0K, 4% free 8302K/8647K, paused 3ms+5ms
12-04 16:28:35.889: D/gralloc_goldfish(553): Emulator without GPU emulation detected.
12-04 16:29:16.819: D/dalvikvm(553): GC_FOR_ALLOC freed 1079K, 14% free 7509K/8711K, paused 221ms
12-04 16:29:16.829: I/dalvikvm-heap(553): Grow heap (frag case) to 8.360MB for 1000016-byte allocation
12-04 16:29:16.889: D/dalvikvm(553): GC_CONCURRENT freed 2K, 3% free 8483K/8711K, paused 4ms+4ms
12-04 16:29:17.229: D/dalvikvm(553): GC_CONCURRENT freed 1016K, 13% free 7979K/9159K, paused 3ms+11ms
12-04 16:29:18.149: E/log_tag(553): Error parsing data org.json.JSONException: No value for Alert
12-04 16:29:20.949: D/dalvikvm(553): GC_CONCURRENT freed 274K, 12% free 8090K/9159K, paused 6ms+5ms
12-04 16:29:26.259: E/log_tag(553): Error parsing data org.json.JSONException: No value for Alert
12-04 16:29:26.859: D/AndroidRuntime(553): Shutting down VM
12-04 16:29:26.859: W/dalvikvm(553): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
12-04 16:29:26.929: E/AndroidRuntime(553): FATAL EXCEPTION: main
12-04 16:29:26.929: E/AndroidRuntime(553): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bombil.kustomizer/com.bombil.kustomizer.Menus}: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:137)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-04 16:29:26.929: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
12-04 16:29:26.929: E/AndroidRuntime(553): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
12-04 16:29:26.929: E/AndroidRuntime(553): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
12-04 16:29:26.929: E/AndroidRuntime(553): at java.util.ArrayList.get(ArrayList.java:304)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddEditText(Menus.java:309)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddInsertView(Menus.java:121)
12-04 16:29:26.929: E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.onCreate(Menus.java:88)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.Activity.performCreate(Activity.java:4465)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-04 16:29:26.929: E/AndroidRuntime(553): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-04 16:29:26.929: E/AndroidRuntime(553): ... 11 more
12-04 16:29:27.009: D/dalvikvm(553): GC_CONCURRENT freed 273K, 10% free 8248K/9159K, paused 4ms+6ms
12-04 16:32:56.799: I/Process(553): Sending signal. PID: 553 SIG: 9
Apparently, you're trying to access an object in an ArrayList at in your Menus.java file at line 309. You're trying to access the object with the index of 2, but the total ArrayList size is only 2, meaning the highest index would be 1. This causes an IndexOutOfBounds exception as shown here:
ComponentInfo{com.bombil.kustomizer/com.bombil.kustomizer.Menus}:
java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
E/AndroidRuntime(553): at com.bombil.kustomizer.Menus.AddEditText(Menus.java:309)
Do you have any objects that are being used by both activities? I know I saw this issue once with a project. One of the activities was messing up the HTTPClient object for the other activity. If you are getting a null exception being thrown try and find the variable. If it is a shared resource for both activities then just make sure to deal with it in a clean way when you exit the second activity.