Someone can explain why the error occurs LISTED AT THE END OF Question, closing the application, when I try to terminate the application through another class:
classe1.class
...
...
AlertDialogManager alert = new AlertDialogManager();
NetworkAvailable internet = new NetworkAvailable();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!internet.isNetworkAvailable(this)){
alert.showAlertDialog(MainActivity.this, "No network!", false);
if (alert.Saindo()){
//ERROR HAPPENS THE FINISH (), I WANTED THAT THIS FUNCTION execute
//AFTER I cancel THERE IN class3.
//The app NOT START, if I let this finish here, but if I withdraw,
//The LOG SPEAK:
Log("Finished", "Closing the application!")
finish();
}
}
}
}
classe2.class:
public class NetworkAvailable{
public boolean isNetworkAvailable (final Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
boolean isAvailable = false;
if(networkInfo != null && networkInfo.isConnected()){
Toast.makeText(context, "CONECTED", Toast.LENGTH_LONG).show();
isAvailable = true;
} else {
Toast.makeText(context, "NO CONECTED", Toast.LENGTH_LONG).show();
isAvailable = false;
}
return isAvailable;
}
}
classe3.class:
public class AlertDialogManager {
public boolean showAlertDialog(final Context context, final String title, final Boolean status) {
if(status == false){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(false);
builder.setTitle(title);
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Log.v("CANCELANDO", "cancelado");
showAlertDialog(context, title, true);
Saindo();
}
});
builder.setPositiveButton("Tentar novamente", new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which)
{
final ConnectivityManager conectivtyManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conectivtyManager.getActiveNetworkInfo() != null
&& conectivtyManager.getActiveNetworkInfo().isAvailable()
&& conectivtyManager.getActiveNetworkInfo().isConnected()) {
}
dialog.dismiss();
showAlertDialog(context, title, false);
}
});
AlertDialog dialog = builder.create(); // calling builder.create after adding buttons
dialog.show();
return status;
}
return status;
}
public boolean Saindo(){
Log.v("SAINDO", "saiu");
return true;
}
}
01-26 22:17:05.721: E/WindowManager(25592): Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#418654f0 that was originally added here
01-26 22:17:05.721: E/WindowManager(25592): android.view.WindowLeaked: Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#418654f0 that was originally added here
01-26 22:17:05.721: E/WindowManager(25592): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:351)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
01-26 22:17:05.721: E/WindowManager(25592): at android.view.Window$LocalWindowManager.addView(Window.java:537)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Dialog.show(Dialog.java:278)
01-26 22:17:05.721: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.AlertDialogManager.showAlertDialog(AlertDialogManager.java:48)
01-26 22:17:05.721: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.onCreate(MainActivity.java:103)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Activity.performCreate(Activity.java:4465)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.access$600(ActivityThread.java:128)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
01-26 22:17:05.721: E/WindowManager(25592): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 22:17:05.721: E/WindowManager(25592): at android.os.Looper.loop(Looper.java:137)
01-26 22:17:05.721: E/WindowManager(25592): at android.app.ActivityThread.main(ActivityThread.java:4514)
01-26 22:17:05.721: E/WindowManager(25592): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 22:17:05.721: E/WindowManager(25592): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 22:17:05.721: E/WindowManager(25592): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-26 22:17:05.721: E/WindowManager(25592): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-26 22:17:05.721: E/WindowManager(25592): at dalvik.system.NativeStart.main(Native Method)
01-26 22:17:05.729: E/WindowManager(25592): Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41776208 that was originally added here
01-26 22:17:05.729: E/WindowManager(25592): android.view.WindowLeaked: Activity ffitteste.favoritos.mapa.rafael.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41776208 that was originally added here
01-26 22:17:05.729: E/WindowManager(25592): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:351)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
01-26 22:17:05.729: E/WindowManager(25592): at android.view.Window$LocalWindowManager.addView(Window.java:537)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Dialog.show(Dialog.java:278)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
01-26 22:17:05.729: E/WindowManager(25592): at ffiteteste.favoritos.servicos.rafael.GPSTracker.showSettingsAlert(GPSTracker.java:194)
01-26 22:17:05.729: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.GPSzoom(MainActivity.java:819)
01-26 22:17:05.729: E/WindowManager(25592): at ffitteste.favoritos.mapa.rafael.MainActivity.onCreate(MainActivity.java:164)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Activity.performCreate(Activity.java:4465)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.access$600(ActivityThread.java:128)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
01-26 22:17:05.729: E/WindowManager(25592): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 22:17:05.729: E/WindowManager(25592): at android.os.Looper.loop(Looper.java:137)
01-26 22:17:05.729: E/WindowManager(25592): at android.app.ActivityThread.main(ActivityThread.java:4514)
01-26 22:17:05.729: E/WindowManager(25592): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 22:17:05.729: E/WindowManager(25592): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 22:17:05.729: E/WindowManager(25592): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-26 22:17:05.729: E/WindowManager(25592): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-26 22:17:05.729: E/WindowManager(25592): at dalvik.system.NativeStart.main(Native Method)
HELPER!
It's a little unclear since you didn't post the actual class names with your code snippets. But it looks like it's because you don't close the Dialog before finishing the Activity here
if (alert.Saindo()){
If you change that to
if (alert.Saindo()){
if (alert != null && alert.isShowing())
alert.dismiss();
it should take care of your problem.
You are finishing the Activity while the Dialog is still showing.
Related
I have popupMenu and CheckBox. I need make write status CheckBox to boolean.
This code not working:
MenuItem fast_result;
boolean fast=false;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.FastResult:
fast_result = item.getSubMenu().getItem(R.id.FastResult);//This is 182 line
fast_result.setChecked(!fast_result.isChecked());
fast=fast_result.isChecked();
return true;
}
}
It is errors:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.alexvsalex.HelpforMath.RootsActivity.onOptionsItemSelected(RootsActivity.java:182)
at android.app.Activity.onMenuItemSelected(Activity.java:2502)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:950)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:163)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
at android.widget.AbsListView$1.run(AbsListView.java:3168)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
What to do?
The problem is solved:
case R.id.FastResult:
fast_result = item; //There was an error
fast_result.setChecked(!fast_result.isChecked());
fast=fast_result.isChecked();
return true;
This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 8 years ago.
I'm new to android application development and i want to send three parameters Latitude ,
Longitude and Bimari(which i am mentioning in
my code below) to phpMyAdmin server via internet.
The problem is that after selecting bimari from
spinner when i click send button my app crashes.
My server side is working correctly.Can anyone
please tell me why i can't send my data to server ?
Thanks alot for reading !
MainActivity.java is as follows:-
public final static String EXTRA_MESSAGE = "com.example.sushma.myfirstapp.MESSAGE";
String nn, nn1, nn2, nn3, nn4, nn5, nnf; // used to make URL
String sss1, sss2; // used to convert lat and long to string
String s; // used to save bimari as string
double lat, lng;
LocationManager lm;
String provider;
Location l;
private View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria c = new Criteria();
provider = lm.getBestProvider(c, false);
l = lm.getLastKnownLocation(provider);
if (l != null) {
//get latitude and longitude of the location
lng = l.getLongitude();
lat = l.getLatitude();
} else {
System.out.println("No lat/long");
}
{
LinearLayout l1 = new LinearLayout(this);
l1.setBackgroundResource(R.drawable.ambulance);
setContentView(R.layout.activity_main);
}
}
public void ongobuttonclick(View view) {
this.view = view;
Spinner sp = (Spinner) findViewById(R.id.problems);
s = sp.getSelectedItem().toString();
sss1 = String.valueOf(lng);
sss2 = String.valueOf(lat);
nn = "http://192.168.2.8/tech/new_predict.php?Latitude=";
nn1 = sss2;
nn2 = "&Longitude=";
nn3 = sss1;
nn4 = "&Bimari=";
nn5 = s;
nnf = nn + nn1 + nn2 + nn3 + nn4 + nn5;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httPost = new HttpPost(nnf);
System.out.println(nnf);
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Logcat
01-26 19:32:22.859 14247-14247/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp D/AndroidRuntime﹕ Shutting down VM
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40da9930)
01-26 19:32:29.105 14247-14247/com.example.sushma.myfirstapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3804)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:842)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.example.sushma.myfirstapp.MainActivity.ongobuttonclick(MainActivity.java:176)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
NewLogcat
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11750: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11756: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 9401: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 534: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 556: Landroid/content/res/TypedArray;.getType (I)I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.947 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 157K, 13% free 8676K/9872K, paused 24ms, total 24ms
01-26 22:45:48.957 23318-23318/com.example.sushma.myfirstapp I/dalvikvm-heap﹕ Grow heap (frag case) to 10.654MB for 1228816-byte allocation
01-26 22:45:48.967 23318-23329/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 11% free 9875K/11076K, paused 14ms, total 14ms
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp E/dalvikvm﹕ adjustAdaptiveCoef max=4194304, min=1048576, ut=568
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_CONCURRENT freed 4K, 11% free 9871K/11076K, paused 16ms+3ms, total 40ms
01-26 22:45:49.257 23318-23318/com.example.sushma.myfirstapp D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init ++
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ gHwMemAllocator client 3
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ **** Using ION allocator ****
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ registered SIGUSR1[10] for pid[23318]
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl Static Counters 0 0
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl[490a9dcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init 490a9dcc--
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/ION﹕ config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/MM_DEVICE﹕ Waiting for mm thread to come up
01-26 22:45:49.277 23318-23346/com.example.sushma.myfirstapp D/MM_DEVICE﹕ mm_device_thread starting
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateContext() config: 18 context: 0x4f3c4db8, VC context 1, Thread 23318
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4beeea48, VC surface: 1, Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/OpenGLRenderer﹕ Enabling debug mode 0
01-26 22:45:50.849 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ Get MotionRecognitionManager
01-26 22:45:50.959 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4c0f1be8, VC surface: 2, Thread: 23318
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:50.989 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:51.079 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:51.089 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.150 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ onDetachedFromWindow
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(NULL) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglDestroySurface() surface: 0x4c0f1be8, android window 0x4c05c8f8, Thread: 23318
01-26 22:45:52.811 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.871 23318-23318/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 22:45:53.802 23318-23318/com.example.sushma.myfirstapp I/System.out﹕ http://192.168.2.8/tech/new_predict.php?Latitude=31.310573780338718&Longitude=75.55498407042245&Bimari=Bones
01-26 22:45:56.945 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.2.8 refused
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at com.example.sushma.myfirstapp.MainActivity$1.run(MainActivity.java:173)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /192.168.2.8 (port 80): connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.Socket.connect(Socket.java:842)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 8 more
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: libcore.io.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.Posix.connect(Native Method)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 13 more
You tried execute httpclient.execute(httPost); method in UI thread. You can not do this.
You can use AsyncTask to resolve this issue.
public void ongobuttonclick(View view) {
...
//your code
//use AsyncTask if you want ot inform ui thread
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httPost = new HttpPost(nnf);
new AsyncTask<HttpPost, Void, HttpResponse>() {
//YourParams, YourProgress, YourResult can be Void
#Override
protected HttpResponse doInBackground(HttpPost... params) {
HttpResponse response = null;
try {
response = httpclient.execute(params[0]);
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
#Override
protected void onPostExecute(HttpResponse response) {
if(response != null){
//do sth in UI thread
}
}
}.execute(httPost);
//or in new thread if you doesn't want ot inform ui thread
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
So I have a spinner, a button and edittext, and according to which item is selected on spinner and which value is in edittext something happens on button click. It used to work perfectly and now it suddenly crashes every time I click the button. I have no idea what I have done to ruin it so I am kindly asking you for some help. I've been stuck like this for hours and I just can't point a finger to what ruined the code.
Button click method (As you can see in case 1, I added shared preferences to a comment just to make sure this isn't what's runing the code):
public void submitQuantityButton (View v){
Button submitButton = (Button)findViewById(R.id.submitButton);
final Spinner sItems = (Spinner)findViewById(R.id.spinner1);
final Context context = this;
final CheckBox cb4 = (CheckBox) findViewById(R.id.checkBox4);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final int position = sItems.getSelectedItemPosition();
EditText quantityEditText = (EditText)findViewById(R.id.editText1);
switch (position){
case 0:
AlertDialog.Builder spinnerErrorBuilder = new AlertDialog.Builder(context);
spinnerErrorBuilder.setTitle("Warning");
spinnerErrorBuilder.setMessage("Please choose an item from the list");
spinnerErrorBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog spinnerError = spinnerErrorBuilder.create();
spinnerError.show();
break;
case 1:
String items = quantityEditText.getText().toString();
cb4.setText("Elaborate Totem (" + items + "/250)");
//saveItemQuantity("cb4", cb4.getText().toString());
break;
}
}
});
}
Button XML:
<Button
android:id="#+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/checkBox25"
android:text="#string/addMaterial"
android:onClick="submitQuantityButton" />
Logcat file:
06-23 15:05:29.276: E/AndroidRuntime(22681): FATAL EXCEPTION: main
06-23 15:05:29.276: E/AndroidRuntime(22681): java.lang.IllegalStateException: Could not execute method of the activity
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.view.View$1.onClick(View.java:3599)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.view.View.performClick(View.java:4204)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.view.View$PerformClick.run(View.java:17355)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.os.Handler.handleCallback(Handler.java:725)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.os.Handler.dispatchMessage(Handler.java:92)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.os.Looper.loop(Looper.java:137)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-23 15:05:29.276: E/AndroidRuntime(22681): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 15:05:29.276: E/AndroidRuntime(22681): at java.lang.reflect.Method.invoke(Method.java:511)
06-23 15:05:29.276: E/AndroidRuntime(22681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-23 15:05:29.276: E/AndroidRuntime(22681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-23 15:05:29.276: E/AndroidRuntime(22681): at dalvik.system.NativeStart.main(Native Method)
06-23 15:05:29.276: E/AndroidRuntime(22681): Caused by: java.lang.reflect.InvocationTargetException
06-23 15:05:29.276: E/AndroidRuntime(22681): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 15:05:29.276: E/AndroidRuntime(22681): at java.lang.reflect.Method.invoke(Method.java:511)
06-23 15:05:29.276: E/AndroidRuntime(22681): at android.view.View$1.onClick(View.java:3594)
06-23 15:05:29.276: E/AndroidRuntime(22681): ... 11 more
06-23 15:05:29.276: E/AndroidRuntime(22681): Caused by: java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.Button
06-23 15:05:29.276: E/AndroidRuntime(22681): at com.example.gw2legendary.Bifrost.submitQuantityButton(Bifrost.java:967)
06-23 15:05:29.276: E/AndroidRuntime(22681): ... 14 more
These kinds of errors normally happen when you have moved two elements inside your layout (switched their places). A Project --> Clean in Eclipse normally resolves this, which makes Android rebuild the R-class.
I have been working on an app to use a phone's/tablet's camera flash as a flashlight. Everything seemed to be working fine but when I tested it on my Droid Bionic running Android 4.1.2, the app failed to turn on the flash even though it said it did. Here is the java code I used:
package com.example.flash;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private boolean isFlashOn = false;
private Camera camera;
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
if(!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
Toast.makeText(getApplicationContext(),
"Your device doesn't have camera!",Toast.LENGTH_SHORT).show();
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (isFlashOn) {
Log.i("info", "torch is turned off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
isFlashOn = false;
button.setText("Tap to turn flashlight on.");
}
else {
Log.i("info", "torch is turned on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
isFlashOn = true;
button.setText("Tap to turn flashlight off.");
}
}
});
}
#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;
}
#Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}}
Is this code correct or did I miss something?
Logcat:
07-03 18:48:29.064: E/Trace(773): error opening trace file: No such file or directory (2)
07-03 18:48:30.535: D/Camera(773): app passed NULL surface
07-03 18:48:31.023: D/libEGL(773): loaded /system/lib/egl/libEGL_emulation.so
07-03 18:48:31.073: D/(773): HostConnection::get() New Host Connection established 0x2a13c3c0, tid 773
07-03 18:48:31.123: D/libEGL(773): loaded /system/lib/egl/libGLESv1_CM_emulation.so
07-03 18:48:31.173: D/libEGL(773): loaded /system/lib/egl/libGLESv2_emulation.so
07-03 18:48:31.406: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:48:31.433: D/OpenGLRenderer(773): Enabling debug mode 0
07-03 18:48:31.723: I/Choreographer(773): Skipped 58 frames! The application may be doing too much work on its main thread.
07-03 18:49:05.923: D/dalvikvm(773): GC_CONCURRENT freed 202K, 12% free 2623K/2956K, paused 74ms+25ms, total 234ms
07-03 18:49:06.216: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:09.584: D/Camera(773): app passed NULL surface
07-03 18:49:09.853: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:11.813: I/info(773): torch is turned on!
07-03 18:49:13.467: I/info(773): torch is turned off!
07-03 18:49:16.263: W/EGL_emulation(773): eglSurfaceAttrib not implemented
07-03 18:49:16.713: D/AndroidRuntime(773): Shutting down VM
07-03 18:49:16.713: W/dalvikvm(773): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-03 18:49:16.936: E/AndroidRuntime(773): FATAL EXCEPTION: main
07-03 18:49:16.936: E/AndroidRuntime(773): java.lang.RuntimeException: Method called after release()
07-03 18:49:16.936: E/AndroidRuntime(773): at android.hardware.Camera._stopPreview(Native Method)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.hardware.Camera.stopPreview(Camera.java:543)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.example.flash.MainActivity.surfaceDestroyed(MainActivity.java:140)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.SurfaceView.updateWindow(SurfaceView.java:553)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:231)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.View.dispatchWindowVisibilityChanged(View.java:7544)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1039)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1211)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer.doFrame(Choreographer.java:532)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Handler.handleCallback(Handler.java:725)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.os.Looper.loop(Looper.java:137)
07-03 18:49:16.936: E/AndroidRuntime(773): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-03 18:49:16.936: E/AndroidRuntime(773): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 18:49:16.936: E/AndroidRuntime(773): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-03 18:49:16.936: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-03 18:49:16.936: E/AndroidRuntime(773): at dalvik.system.NativeStart.main(Native Method)
07-03 18:49:24.854: E/Trace(811): error opening trace file: No such file or directory (2)
07-03 18:49:25.413: D/libEGL(811): loaded /system/lib/egl/libEGL_emulation.so
07-03 18:49:25.567: D/(811): HostConnection::get() New Host Connection established 0x2a15f570, tid 811
07-03 18:49:25.643: D/libEGL(811): loaded /system/lib/egl/libGLESv1_CM_emulation.so
07-03 18:49:25.663: D/libEGL(811): loaded /system/lib/egl/libGLESv2_emulation.so
07-03 18:49:25.934: W/EGL_emulation(811): eglSurfaceAttrib not implemented
07-03 18:49:25.963: D/OpenGLRenderer(811): Enabling debug mode 0
07-03 18:53:12.298: D/Camera(811): app passed NULL surface
07-03 18:53:12.723: D/dalvikvm(811): GC_CONCURRENT freed 172K, 11% free 2600K/2904K, paused 9ms+165ms, total 421ms
07-03 18:53:12.934: E/EGL_emulation(811): rcCreateWindowSurface returned 0
07-03 18:53:12.934: E/EGL_emulation(811): tid 811: eglCreateWindowSurface(631): error 0x3003 (EGL_BAD_ALLOC)
07-03 18:53:12.943: D/AndroidRuntime(811): Shutting down VM
07-03 18:53:12.943: W/dalvikvm(811): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-03 18:53:13.033: E/AndroidRuntime(811): FATAL EXCEPTION: main
07-03 18:53:13.033: E/AndroidRuntime(811): java.lang.RuntimeException: createWindowSurface failed EGL_BAD_ALLOC
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1064)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:961)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:787)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1502)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer.doFrame(Choreographer.java:532)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Handler.handleCallback(Handler.java:725)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.os.Looper.loop(Looper.java:137)
07-03 18:53:13.033: E/AndroidRuntime(811): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-03 18:53:13.033: E/AndroidRuntime(811): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 18:53:13.033: E/AndroidRuntime(811): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 18:53:13.033: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-03 18:53:13.033: E/AndroidRuntime(811): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-03 18:53:13.033: E/AndroidRuntime(811): at dalvik.system.NativeStart.main(Native Method)
UPDATE
I think the key is you are running Android 4.1.2. Since Android 4.0, if you want to use the Camera Device, even if you only want to use the flash, you are forced to use a SurfaceView.
In the previous answer (below), I gave you a link to a Torch app which uses SurfaceView. Try it or adapt it to your code.
PREVIOUS ANSWER:
As stated in many other cases (like this one), you may be facing a Device-Specific issue that is quite common in the Android world.
Although getSupportedFlashModes() may return FLASH_MODE_TORCH on nearly every device, many of them don't actually support it.
Anyway, you could try these:
Use camera.startPreview(); after camera = Camera.open();
Try setting FLASH_MODE_OFF initially (before camera.startPreview();).
Check if this Torch app works in your device. In case it does, you have the source code to compare it to yours.
Download a Torch app from the Play Store to test if it's a device issue or not.
Post the issue in a Droid Bionic support forum.
UPDATE: I would say the final keyword is a problem in your code. Try changing it to:
//camera = Camera.open();
//final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (isFlashOn) {
Log.i("info", "torch is turned off!");
cam.stopPreview();
cam.release();
isFlashOn = false;
button.setText("Tap to turn flashlight on.");
}
else {
Log.i("info", "torch is turned on!");
camera = Camera.open();
Parameters p = camera.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.startPreview();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
isFlashOn = true;
button.setText("Tap to turn flashlight off.");
}
}
});
user the permission "android.permission.FLASHLIGHT" in the manifest
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
I'm build a app that consist of user login and registration but every time I test it on the emulator I receive a force close. Below are the errors I'm receiving in the log cat:
08-14 14:06:28.853: D/dalvikvm(828): GC_FOR_ALLOC freed 108K, 3% free 8262K/8455K, paused 89ms, total 92ms
08-14 14:06:29.273: I/Choreographer(828): Skipped 72 frames! The application may be doing too much work on its main thread.
08-14 14:06:29.373: D/gralloc_goldfish(828): Emulator without GPU emulation detected.
08-14 14:06:29.373: D/dalvikvm(828): GC_CONCURRENT freed 5K, 3% free 8660K/8839K, paused 110ms+28ms, total 365ms
08-14 14:06:29.902: I/Choreographer(828): Skipped 85 frames! The application may be doing too much work on its main thread.
08-14 14:06:32.533: D/dalvikvm(828): GC_CONCURRENT freed 32K, 3% free 9027K/9223K, paused 81ms+111ms, total 343ms
08-14 14:06:32.813: I/Choreographer(828): Skipped 71 frames! The application may be doing too much work on its main thread.
08-14 14:06:33.303: I/Choreographer(828): Skipped 38 frames! The application may be doing too much work on its main thread.
08-14 14:06:39.854: D/InputEventConsistencyVerifier(828): KeyEvent: ACTION_UP but key was not down.
08-14 14:06:39.854: D/InputEventConsistencyVerifier(828): in android.widget.EditText#412b2f68
08-14 14:06:39.854: D/InputEventConsistencyVerifier(828): 0: sent at 1614282000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_M, scanCode=50, metaState=0, flags=0x8, repeatCount=0, eventTime=1614282, downTime=1614282, deviceId=0, source=0x301 }
08-14 14:06:39.874: D/InputEventConsistencyVerifier(828): KeyEvent: ACTION_UP but key was not down.
08-14 14:06:39.874: D/InputEventConsistencyVerifier(828): in android.widget.EditText#412b2f68
08-14 14:06:39.874: D/InputEventConsistencyVerifier(828): 0: sent at 1614392000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=1614392, downTime=1614282, deviceId=0, source=0x301 }
08-14 14:06:39.874: D/InputEventConsistencyVerifier(828): -- recent events --
08-14 14:06:39.874: D/InputEventConsistencyVerifier(828): 1: sent at 1614282000000, (unhandled) KeyEvent { action=ACTION_UP, keyCode=KEYCODE_M, scanCode=50, metaState=0, flags=0x80000008, repeatCount=0, eventTime=1614282, downTime=1614282, deviceId=0, source=0x301 }
08-14 14:07:02.362: D/AndroidRuntime(828): Shutting down VM
08-14 14:07:02.362: W/dalvikvm(828): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
**08-14 14:07:02.472: E/AndroidRuntime(828): FATAL EXCEPTION: main
08-14 14:07:02.472: E/AndroidRuntime(828): android.os.NetworkOnMainThreadException
08-14 14:07:02.472: E/AndroidRuntime(828): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
08-14 14:07:02.472: E/AndroidRuntime(828): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
08-14 14:07:02.472: E/AndroidRuntime(828): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
08-14 14:07:02.472: E/AndroidRuntime(828): at libcore.io.IoBridge.connect(IoBridge.java:112)
08-14 14:07:02.472: E/AndroidRuntime(828): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
08-14 14:07:02.472: E/AndroidRuntime(828): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
08-14 14:07:02.472: E/AndroidRuntime(828): at java.net.Socket.connect(Socket.java:842)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-14 14:07:02.472: E/AndroidRuntime(828): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-14 14:07:02.472: E/AndroidRuntime(828): at library.JSONParser.getJSONFromUrl(JSONParser.java:41)
08-14 14:07:02.472: E/AndroidRuntime(828): at library.UserFunctions.loginUser(UserFunctions.java:40)
08-14 14:07:02.472: E/AndroidRuntime(828): at com.thryfting.www.LoginActivity.onClick(LoginActivity.java:66)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.view.View.performClick(View.java:4084)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.view.View$PerformClick.run(View.java:16966)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.os.Handler.handleCallback(Handler.java:615)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.os.Looper.loop(Looper.java:137)
08-14 14:07:02.472: E/AndroidRuntime(828): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-14 14:07:02.472: E/AndroidRuntime(828): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 14:07:02.472: E/AndroidRuntime(828): at java.lang.reflect.Method.invoke(Method.java:511)
08-14 14:07:02.472: E/AndroidRuntime(828): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-14 14:07:02.472: E/AndroidRuntime(828): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-14 14:07:02.472: E/AndroidRuntime(828): at dalvik.system.NativeStart.main(Native Method)**
Updated code for register activity:
package com.thryfting.www;
import org.json.JSONException;
import org.json.JSONObject;
import library.DatabaseHandler;
import library.UserFunctions;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
public class RegisterActivity extends SherlockActivity implements OnClickListener{
Button btnRegister;
EditText inputFullName;
EditText inputEmail;
EditText inputPassword;
TextView registerErrorMsg;
TextView loginScreen;
//JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_EMAIL = "email";
private static String KEY_CREATED_AT = "created_at";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
loginScreen = (TextView) findViewById(R.id.link_to_login);
inputEmail = (EditText) findViewById(R.id.etemailSignup);
inputPassword = (EditText) findViewById(R.id.etPasswordSignup);
inputFullName = (EditText) findViewById(R.id.etFullnameSignup);
btnRegister = (Button) findViewById(R.id.btnRegister);
registerErrorMsg = (TextView) findViewById(R.id.register_error);
loginScreen.setOnClickListener(this);
btnRegister.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btnRegister:
new register().execute(KEY_SUCCESS);
break;
case R.id.link_to_login:
Intent i = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(i);
//Close Registration View
finish();
break;
}
}
public class register extends AsyncTask<String, Integer, String>{
#Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String name = inputFullName.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(name, email, password);
try{
if(json.getString(KEY_SUCCESS) != null){
registerErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
//user successfully registered
// Store user details in SQLite Database
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
//Clear all previous data in database
userFunction.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));
}else{
//Error in registration
registerErrorMsg.setText("Error occured in registration");
}
}
} catch(JSONException e){
e.printStackTrace();
} finally{
//Launch Dashboard
Intent dashboard = new Intent (getApplicationContext(), Timeline.class);
//Close all views before launching Dashboard
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//Close registration screen
finish();
}
return null;
}
}
}
New error messages below:
08-15 14:53:32.940: W/dalvikvm(865): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
08-15 14:53:33.060: E/AndroidRuntime(865): FATAL EXCEPTION: AsyncTask #1
08-15 14:53:33.060: E/AndroidRuntime(865): java.lang.RuntimeException: An error occured while executing doInBackground()
08-15 14:53:33.060: E/AndroidRuntime(865): at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-15 14:53:33.060: E/AndroidRuntime(865): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.lang.Thread.run(Thread.java:856)
08-15 14:53:33.060: E/AndroidRuntime(865): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=register
08-15 14:53:33.060: E/AndroidRuntime(865): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
08-15 14:53:33.060: E/AndroidRuntime(865): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
08-15 14:53:33.060: E/AndroidRuntime(865): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-15 14:53:33.060: E/AndroidRuntime(865): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-15 14:53:33.060: E/AndroidRuntime(865): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-15 14:53:33.060: E/AndroidRuntime(865): at library.JSONParser.getJSONFromUrl(JSONParser.java:41)
08-15 14:53:33.060: E/AndroidRuntime(865): at library.UserFunctions.registerUser(UserFunctions.java:63)
08-15 14:53:33.060: E/AndroidRuntime(865): at com.thryfting.www.RegisterActivity$register.doInBackground(RegisterActivity.java:89)
08-15 14:53:33.060: E/AndroidRuntime(865): at com.thryfting.www.RegisterActivity$register.doInBackground(RegisterActivity.java:1)
08-15 14:53:33.060: E/AndroidRuntime(865): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-15 14:53:33.060: E/AndroidRuntime(865): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-15 14:53:33.060: E/AndroidRuntime(865): ... 5 more
08-15 14:53:34.812: I/Choreographer(865): Skipped 93 frames! The application may be doing too much work on its main thread.
08-15 14:53:36.512: I/Process(865): Sending signal. PID: 865 SIG: 9
public JSONObject registerUser(String name, String email, String password){
//building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", register_tag));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
//Getting JSON object
JSONObject json = jsonParser.getJSONFromUrl(register_tag, params);
//return json
return json;
}
Your getting a StrictMode violation. This means that you are doing something blocking on the UI Thread. Hence the reason for
android.os.NetworkOnMainThreadException
From the rest of your LOG it appears your performing a web request.
Make sure that HTTP request is wrapped in an AsyncTask (or something similar)
It seems like you are trying to do your login and registration on the main Thread. First of all this is bad practice, and it can't be done on recent API levels.
All you need to do is make your network connections in a separate thread, be it an AsyncTask or just a plain old Thread()
as an example :
use this
public void login()
{
new Thread(new Runnable() {
#Override
public void run() {
//your network connection goes here
}
}).start();
}
instead of :
public void login()
{
//your network connection goes here
}
Try to check the same in a mobile with internet connectivity.
The logcat also displays that the emulator doesnt has a GPS connectivity.