java.io.IOException: Is a directory Android - android

I am trying to insert images from the drawable folder to ImageView on custom listview. But when i set the images on satisfying the condition its giving the following warnings from getView.
12-27 11:56:56.356: DEBUG/skia(341): ---- read threw an exception
12-27 11:56:56.366: WARN/System.err(341): java.io.IOException: Is a directory
12-27 11:56:56.366: WARN/System.err(341): at org.apache.harmony.luni.platform.OSFileSystem.read(Native Method)
12-27 11:56:56.366: WARN/System.err(341): at dalvik.system.BlockGuard$WrappedFileSystem.read(BlockGuard.java:165)
12-27 11:56:56.366: WARN/System.err(341): at java.io.FileInputStream.read(FileInputStream.java:290)
12-27 11:56:56.366: WARN/System.err(341): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:166)
12-27 11:56:56.366: WARN/System.err(341): at java.io.BufferedInputStream.read(BufferedInputStream.java:324)
12-27 11:56:56.366: WARN/System.err(341): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-27 11:56:56.366: WARN/System.err(341): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
12-27 11:56:56.378: WARN/System.err(341): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284)
12-27 11:56:56.378: WARN/System.err(341): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:309)
12-27 11:56:56.378: WARN/System.err(341): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:800)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.ImageView.resolveUri(ImageView.java:528)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.ImageView.setImageURI(ImageView.java:305)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.SimpleAdapter.setViewImage(SimpleAdapter.java:264)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:192)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
12-27 11:56:56.378: WARN/System.err(341): at com.presentation.activity.ShowListActivity$CustomAdapter.getView(ShowListActivity.java:229)
12-27 11:56:56.378: WARN/System.err(341): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.ListView.makeAndAddView(ListView.java:1745)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.ListView.fillDown(ListView.java:670)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.ListView.fillFromTop(ListView.java:727)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.ListView.layoutChildren(ListView.java:1598)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
12-27 11:56:56.386: WARN/System.err(341): at android.view.View.layout(View.java:7175)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
12-27 11:56:56.386: WARN/System.err(341): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
12-27 11:56:56.396: WARN/System.err(341): at android.view.View.layout(View.java:7175)
12-27 11:56:56.396: WARN/System.err(341): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-27 11:56:56.396: WARN/System.err(341): at android.view.View.layout(View.java:7175)
12-27 11:56:56.396: WARN/System.err(341): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
12-27 11:56:56.396: WARN/System.err(341): at android.view.View.layout(View.java:7175)
12-27 11:56:56.396: WARN/System.err(341): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
12-27 11:56:56.396: WARN/System.err(341): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
12-27 11:56:56.396: WARN/System.err(341): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 11:56:56.396: WARN/System.err(341): at android.os.Looper.loop(Looper.java:123)
12-27 11:56:56.396: WARN/System.err(341): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-27 11:56:56.396: WARN/System.err(341): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 11:56:56.396: WARN/System.err(341): at java.lang.reflect.Method.invoke(Method.java:507)
12-27 11:56:56.396: WARN/System.err(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-27 11:56:56.406: WARN/System.err(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-27 11:56:56.406: WARN/System.err(341): at dalvik.system.NativeStart.main(Native Method)
12-27 11:56:56.466: WARN/System.err(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-27 11:56:56.406: WARN/System.err(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-27 11:56:56.466: DEBUG/skia(341): ---- read threw an exception
12-27 11:56:56.466: DEBUG/skia(341): --- SkImageDecoder::Factory returned null
12-27 11:56:56.466: INFO/System.out(341): resolveUri failed on bad bitmap uri:
I am using a custom adapter that extends the SimpleAdapter and putting the text and icons according to condition.
My custome adapter looks something like..
serviceAdapter = new CustomAdapter(this, serviceList, R.layout.list_row,
new String[] { "name", "duration","reason", "remark", "img1", "img2", "img3",
"img" }, new int[] { R.id.servicename, R.id.duration,R.id.reason, R.id.remark,
R.id.statusImg1, R.id.statusImg2, R.id.statusImg3, R.id.isExpandable });
I am putting the corresponding values from a HashMap...
HashMap<String, Object> rowValue = new HashMap<String, Object>();
And image using. rowValue.put("img2", R.drawable.img);
Its not throwing any errors but slowing down the application a lot. Can any one let me know what the problem might be...

Check for the image name in image path. The issue may be in image path. I am sure that it points to any directory not to file.

maybe the problem is: the image file path pointer to a folder not file

Related

how to Extending the WebView correctly?

I'm using solution of Scroll webview horizontally inside a ViewPager
it's looks very useful, I was reference ExtendedWebView in xml,
<ExtendedWebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
instance ExtendedWebView in .class,
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = mInflater.inflate(R.layout.lay1, null);
ExtendedWebView webView = (ExtendedWebView)layout.findViewById(R.id.webview);
but i got 'Error inflating class ExtendedWebView', so could anybody to help me to give me some ideas, thanks for your time and experience!
heres are entire stack trace,
12-27 22:14:44.263: E/AndroidRuntime(10824): FATAL EXCEPTION: main
12-27 22:14:44.263: E/AndroidRuntime(10824): android.view.InflateException: Binary XML file line #7: Error inflating class com.vv_package_name.ExtendedWebView
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-27 22:14:44.263: E/AndroidRuntime(10824): at com.vv_package_name.vv_main$ExtendedPagerAdapter.instantiateItem(vv_main.java:135)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.support.v4.view.ViewPager.populate(ViewPager.java:930)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.os.Looper.loop(Looper.java:123)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 22:14:44.263: E/AndroidRuntime(10824): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 22:14:44.263: E/AndroidRuntime(10824): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 22:14:44.263: E/AndroidRuntime(10824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-27 22:14:44.263: E/AndroidRuntime(10824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-27 22:14:44.263: E/AndroidRuntime(10824): at dalvik.system.NativeStart.main(Native Method)
12-27 22:14:44.263: E/AndroidRuntime(10824): Caused by: java.lang.ClassNotFoundException: com.vv_package_name.ExtendedWebView in loader dalvik.system.PathClassLoader[/data/app/com.vv_package_name-2.apk]
12-27 22:14:44.263: E/AndroidRuntime(10824): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-27 22:14:44.263: E/AndroidRuntime(10824): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-27 22:14:44.263: E/AndroidRuntime(10824): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
12-27 22:14:44.263: E/AndroidRuntime(10824): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
12-27 22:14:44.263: E/AndroidRuntime(10824): ... 33 more
if using WebView instead of ExtendedWebView, my code is working fine :)
You need to provide a full reference to the class, including the package.
For instance,
<org.example.myapp.ExtendedWebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
sorry i'm a noob, it's my problem, i put these extend webview code in main Activity class in one .class file...it should be save with a standalone .class file...:)
public class ExtendedWebView extends WebView {
Solved for me by using this in my XML:
<view
class="com.example.MainActivity$MyWebView"
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Android: App stops working after requesting location updates in android simulator

My app stopped working after requesting location updates in android emulator. This happens only for android versions over 3.0.
Any code like the following
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
the app stops working. Is this a regular behavior in simulator for these versions or am I doing something wrong?
More info: If I launch the simulator for android 2.3 or less, the exceptions are being caught properly. This is not happening in the other versions.
12-27 19:17:59.183: W/dalvikvm(640): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-27 19:17:59.253: E/AndroidRuntime(640): FATAL EXCEPTION: main
12-27 19:17:59.253: E/AndroidRuntime(640): android.os.NetworkOnMainThreadException
12-27 19:17:59.253: E/AndroidRuntime(640): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
12-27 19:17:59.253: E/AndroidRuntime(640): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
12-27 19:17:59.253: E/AndroidRuntime(640): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-27 19:17:59.253: E/AndroidRuntime(640): at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-27 19:17:59.253: E/AndroidRuntime(640): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-27 19:17:59.253: E/AndroidRuntime(640): at com.rahul.places.AddNewLocation.getUrlArray(AddNewLocation.java:147)
12-27 19:17:59.253: E/AndroidRuntime(640): at com.rahul.places.AddNewLocation.access$6(AddNewLocation.java:139)
12-27 19:17:59.253: E/AndroidRuntime(640): at com.rahul.places.AddNewLocation$2.onClick(AddNewLocation.java:69)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.view.View.performClick(View.java:4084)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.view.View$PerformClick.run(View.java:16966)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.os.Handler.handleCallback(Handler.java:615)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.os.Handler.dispatchMessage(Handler.java:92)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.os.Looper.loop(Looper.java:137)
12-27 19:17:59.253: E/AndroidRuntime(640): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-27 19:17:59.253: E/AndroidRuntime(640): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 19:17:59.253: E/AndroidRuntime(640): at java.lang.reflect.Method.invoke(Method.java:511)
12-27 19:17:59.253: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-27 19:17:59.253: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-27 19:17:59.253: E/AndroidRuntime(640): at dalvik.system.NativeStart.main(Native Method)
This is expected. Android is much more strict in dealing with work on the UI thread in more recent versions.
The solution is to use a handler to change the UI on the UI thread when location updates are available (that is in your onLocationChanged() method).

Android http-request causes Error - sitting since 3 days

I am sitting since 3 days, looking everywhere on net but it dosnt work ... every time I try to make a http-request on android: it comes the error: unfourtunately, ... has stopped. here my code:
package sd.s;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SdsdActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread trd = new Thread(new Runnable(){
public void run(){
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(
"http://www.test.com");
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("test", "test"));
nameValuePair.add(new BasicNameValuePair("message",
"Hi, trying Android HTTP post!"));
// Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpClient.execute(httpPost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
} });
trd.run();
}
}
here my output on LogCat
02-24 17:53:39.003: D/dalvikvm(516): Not late-enabling CheckJNI (already on)
02-24 17:53:40.293: D/AndroidRuntime(516): Shutting down VM
02-24 17:53:40.304: W/dalvikvm(516): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 17:53:40.313: E/AndroidRuntime(516): FATAL EXCEPTION: main
02-24 17:53:40.313: E/AndroidRuntime(516): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.Looper.loop(Looper.java:137)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 17:53:40.313: E/AndroidRuntime(516): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 17:53:40.313: E/AndroidRuntime(516): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 17:53:40.313: E/AndroidRuntime(516): at dalvik.system.NativeStart.main(Native Method)
02-24 17:53:40.313: E/AndroidRuntime(516): Caused by: android.os.NetworkOnMainThreadException
02-24 17:53:40.313: E/AndroidRuntime(516): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 17:53:40.313: E/AndroidRuntime(516): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 17:53:40.313: E/AndroidRuntime(516): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 17:53:40.313: E/AndroidRuntime(516): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:52)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.Activity.performCreate(Activity.java:4465)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 17:53:40.313: E/AndroidRuntime(516): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 17:53:40.313: E/AndroidRuntime(516): ... 11 more
02-24 17:59:31.783: D/AndroidRuntime(584): Shutting down VM
02-24 17:59:31.783: W/dalvikvm(584): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 17:59:31.793: E/AndroidRuntime(584): FATAL EXCEPTION: main
02-24 17:59:31.793: E/AndroidRuntime(584): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.Looper.loop(Looper.java:137)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 17:59:31.793: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 17:59:31.793: E/AndroidRuntime(584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 17:59:31.793: E/AndroidRuntime(584): at dalvik.system.NativeStart.main(Native Method)
02-24 17:59:31.793: E/AndroidRuntime(584): Caused by: android.os.NetworkOnMainThreadException
02-24 17:59:31.793: E/AndroidRuntime(584): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 17:59:31.793: E/AndroidRuntime(584): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 17:59:31.793: E/AndroidRuntime(584): at sd.s.SdsdActivity$1.run(SdsdActivity.java:53)
02-24 17:59:31.793: E/AndroidRuntime(584): at java.lang.Thread.run(Thread.java:856)
02-24 17:59:31.793: E/AndroidRuntime(584): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:66)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.Activity.performCreate(Activity.java:4465)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 17:59:31.793: E/AndroidRuntime(584): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 17:59:31.793: E/AndroidRuntime(584): ... 11 more
02-24 18:08:12.242: D/AndroidRuntime(626): Shutting down VM
02-24 18:08:12.242: W/dalvikvm(626): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
02-24 18:08:12.262: E/AndroidRuntime(626): FATAL EXCEPTION: main
02-24 18:08:12.262: E/AndroidRuntime(626): java.lang.RuntimeException: Unable to start activity ComponentInfo{sd.s/sd.s.SdsdActivity}: android.os.NetworkOnMainThreadException
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.Looper.loop(Looper.java:137)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.reflect.Method.invoke(Method.java:511)
02-24 18:08:12.262: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-24 18:08:12.262: E/AndroidRuntime(626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-24 18:08:12.262: E/AndroidRuntime(626): at dalvik.system.NativeStart.main(Native Method)
02-24 18:08:12.262: E/AndroidRuntime(626): Caused by: android.os.NetworkOnMainThreadException
02-24 18:08:12.262: E/AndroidRuntime(626): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-24 18:08:12.262: E/AndroidRuntime(626): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-24 18:08:12.262: E/AndroidRuntime(626): at sd.s.SdsdActivity$1.run(SdsdActivity.java:53)
02-24 18:08:12.262: E/AndroidRuntime(626): at java.lang.Thread.run(Thread.java:856)
02-24 18:08:12.262: E/AndroidRuntime(626): at sd.s.SdsdActivity.onCreate(SdsdActivity.java:66)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.Activity.performCreate(Activity.java:4465)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-24 18:08:12.262: E/AndroidRuntime(626): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-24 18:08:12.262: E/AndroidRuntime(626): ... 11 more
Maybe I am to stupid but since 3 days I trying to get it running, The Applications starts, but stops after start everytime ...
Permission Internet is done and Firewall is np > WebBrowser in emulator works as well, what is wrong? pls - thank you very much for every answer!
You are executing the run() method of your Thread object on the main thread. Replace this:
trd.run();
with this:
trd.start();
As of Android 3.0, you cannot perform this type of request on the main thread.
NetworkOnMainThreadException
Class Overview
The exception that is thrown when an application attempts to perform a networking operation on its main thread.
This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged. See the document Designing for Responsiveness.
Also see StrictMode.
See http://developer.android.com/guide/practices/design/responsiveness.html for guidelines on building responsive applications.
From your log, it looks like the error is android.os.NetworkOnMainThreadException. From http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html, it sounds like the error is that you're trying to do network operations in your main thread. Since this can make your UI unresponsive, it's discouraged. And since you seem to be running in strict mode (http://developer.android.com/reference/android/os/StrictMode.html), it's crashing the app.
Also, you should be calling trd.start() instead of trd.run()

Android Error when closing the application

I have an android programm which manage a database. It this database, I write the sensor values of my device.
When close the application with the home button, i have a force close error.
Here is my logcat, can you please help me, thank you.
`12-27 10:45:20.827: D/AndroidRuntime(1053): Shutting down VM
12-27 10:45:20.827: W/dalvikvm(1053): threadid=1: thread exiting with uncaught exception (group=0x40014760)
12-27 10:45:20.942: E/AndroidRuntime(1053): FATAL EXCEPTION: main
12-27 10:45:20.942: E/AndroidRuntime(1053): java.lang.NullPointerException
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:283)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:116)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1732)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1605)
12-27 10:45:20.942: E/AndroidRuntime(1053): at milos.stationdemesure.CapteursBDD.insertValeursCapteur(CapteursBDD.java:69)
12-27 10:45:20.942: E/AndroidRuntime(1053): at milos.stationdemesure.EssaisCapteurs.onProximityChanged(EssaisCapteurs.java:454)
12-27 10:45:20.942: E/AndroidRuntime(1053): at milos.stationdemesure.EssaisCapteurs.onSensorChanged(EssaisCapteurs.java:354)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:529)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.os.Looper.loop(Looper.java:126)
12-27 10:45:20.942: E/AndroidRuntime(1053): at android.app.ActivityThread.main(ActivityThread.java:3997)
12-27 10:45:20.942: E/AndroidRuntime(1053): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 10:45:20.942: E/AndroidRuntime(1053): at java.lang.reflect.Method.invoke(Method.java:491)
12-27 10:45:20.942: E/AndroidRuntime(1053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-27 10:45:20.942: E/AndroidRuntime(1053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-27 10:45:20.942: E/AndroidRuntime(1053): at dalvik.system.NativeStart.main(Native Method)
`
I feel the issue is either database instance or any other object became null but you are calling some method using that object. Always check for null before using any methods of any object. see the sample example
example
if(database != null){
database.close();
}
Looks similar to this issue: SQLiteDatabase close() function causing NullPointerException when multiple threads
You may not need to call database.close()

After starting activity the activity crashes. Textview and string involved

i have a spinner and when you select an item from the spinner a text from a string should show in the textView, (txtdescription1) but when i start the activity it crashes.
i have tested a lot of thing but i dont find a error in the code.
Resources res = getResources();
int[] txt = res.getIntArray(R.array.description);
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
txtdescription1.setText(txt[position]);
}
Here is the LogCat
12-27 00:37:24.895: E/AndroidRuntime(1267): FATAL EXCEPTION: main
12-27 00:37:24.895: E/AndroidRuntime(1267): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.alpha.liveshit/com.alpha.liveshit.Sample}: java.lang.NullPointerException
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.os.Looper.loop(Looper.java:123)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 00:37:24.895: E/AndroidRuntime(1267): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 00:37:24.895: E/AndroidRuntime(1267): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 00:37:24.895: E/AndroidRuntime(1267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-27 00:37:24.895: E/AndroidRuntime(1267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-27 00:37:24.895: E/AndroidRuntime(1267): at dalvik.system.NativeStart.main(Native Method)
12-27 00:37:24.895: E/AndroidRuntime(1267): Caused by: java.lang.NullPointerException
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
12-27 00:37:24.895: E/AndroidRuntime(1267): at com.alpha.liveshit.Sample.<init>(Sample.java:42)
12-27 00:37:24.895: E/AndroidRuntime(1267): at java.lang.Class.newInstanceImpl(Native Method)
12-27 00:37:24.895: E/AndroidRuntime(1267): at java.lang.Class.newInstance(Class.java:1429)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-27 00:37:24.895: E/AndroidRuntime(1267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-27 00:37:24.895: E/AndroidRuntime(1267): ... 11 more
You appear to be calling getResources() from your activity's constructor. Your activity should not have a constructor (or, at least, not one that interacts with the framework in any way). It hasn't been properly initialized at that point (which is why the call to getResources() is throwing a NPE). Put all your initialization code in onCreate(Bundle).

Categories

Resources