Simulator Crashes with TextView and ImageView - android

I recently started programing and when I did a basic ImageView and TextView shown below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
<ImageView
android:id="#+id/joe"
android:src="#drawable/joe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
The simulator crashed and the logcat gave this error:
11-24 11:09:20.938: D/AndroidRuntime(713): Shutting down VM
11-24 11:09:20.938: W/dalvikvm(713): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
11-24 11:09:20.938: E/AndroidRuntime(713): Uncaught handler: thread main exiting due to uncaught exception
11-24 11:09:20.958: E/AndroidRuntime(713): java.lang.RuntimeException: Unable to start activity ComponentInfo{tristan.wuker.wrje/tristan.wuker.wrje.MrttestActivity}: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute.
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.os.Looper.loop(Looper.java:123)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.main(ActivityThread.java:4203)
11-24 11:09:20.958: E/AndroidRuntime(713): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 11:09:20.958: E/AndroidRuntime(713): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
11-24 11:09:20.958: E/AndroidRuntime(713): at dalvik.system.NativeStart.main(Native Method)
11-24 11:09:20.958: E/AndroidRuntime(713): Caused by: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute.
11-24 11:09:20.958: E/AndroidRuntime(713): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:438)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3433)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3513)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1265)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1191)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:45)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.rInflate(LayoutInflater.java:619)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-24 11:09:20.958: E/AndroidRuntime(713): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.Activity.setContentView(Activity.java:1620)
11-24 11:09:20.958: E/AndroidRuntime(713): at tristan.wuker.wrje.MrttestActivity.onCreate(MrttestActivity.java:11)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
11-24 11:09:20.958: E/AndroidRuntime(713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
11-24 11:09:20.958: E/AndroidRuntime(713): ... 11 more
11-24 11:09:20.978: I/dalvikvm(713): threadid=7: reacting to signal 3
11-24 11:09:20.978: E/dalvikvm(713): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
I am also new to this website so I am sorry if I posted this wrong.
Also if it helps to know, when I take out ImageView the text works like a charm.

As I am sure you figured out in the end, the logs tell you where the problem is. Specifically this line (that I shortened so it fits):
11-24 11:09:20.958 .. Caused by.. #10: You must supply a layout_width attribute.
As you can see in the snippet below:
<TextView>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
You closed the <TextView\> element too early, before specifying any attributes. The one that log mentions is _layout_width_.
All you have to do to fix this 'issue' is remove the right shevron from the TextView element opening, like this:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>
Boom, done :)
PS: One teeny tiny detail though fill_parent is depreciated, you should use match_parent instead:
<TextView>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
</TextView>

I tried your code just now and seems to work when I take out the closing </TextView> tag:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/texttry" />
<ImageView
android:id="#+id/joe"
android:src="#drawable/joe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

Related

Decompiled and imported into Eclipse and got instantiation error

I am a newbie to Android App programming. I decompiled an APK and imported into Eclipse. I ran it on an Android emulator and I got the message below on Logcat. Can someone give me an idea where to start looking. The app works on the Android phone. Thanks.
11-24 13:41:39.046: D/AndroidRuntime(363): Shutting down VM
11-24 13:41:39.046: W/dalvikvm(363): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-24 13:41:39.126: E/AndroidRuntime(363): FATAL EXCEPTION: main
11-24 13:41:39.126: E/AndroidRuntime(363): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.breakeven/com.breakeven.BreakEvenCalculatorActivity}: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.os.Looper.loop(Looper.java:123)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:41:39.126: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:41:39.126: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:41:39.126: E/AndroidRuntime(363): at dalvik.system.NativeStart.main(Native Method)
11-24 13:41:39.126: E/AndroidRuntime(363): Caused by: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:41:39.126: E/AndroidRuntime(363): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-24 13:41:39.126: E/AndroidRuntime(363): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-24 13:41:39.126: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-24 13:41:39.126: E/AndroidRuntime(363): ... 11 more
11-24 13:43:41.106: I/Process(363): Sending signal. PID: 363 SIG: 9
11-24 13:44:17.136: D/AndroidRuntime(393): Shutting down VM
11-24 13:44:17.136: W/dalvikvm(393): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-24 13:44:17.206: E/AndroidRuntime(393): FATAL EXCEPTION: main
11-24 13:44:17.206: E/AndroidRuntime(393): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.breakeven/com.breakeven.BreakEvenCalculatorActivity}: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.os.Looper.loop(Looper.java:123)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:17.206: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:17.206: E/AndroidRuntime(393): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:17.206: E/AndroidRuntime(393): at dalvik.system.NativeStart.main(Native Method)
11-24 13:44:17.206: E/AndroidRuntime(393): Caused by: java.lang.ClassNotFoundException: com.breakeven.BreakEvenCalculatorActivity in loader dalvik.system.PathClassLoader[/data/app/com.breakeven-1.apk]
11-24 13:44:17.206: E/AndroidRuntime(393): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-24 13:44:17.206: E/AndroidRuntime(393): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-24 13:44:17.206: E/AndroidRuntime(393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
11-24 13:44:17.206: E/AndroidRuntime(393): ... 11 more
11-24 13:44:23.546: I/Process(393): Sending signal. PID: 393 SIG: 9
11-24 13:49:28.816: D/AndroidRuntime(403): Shutting down VM
11-24 13:49:28.816: W/dalvikvm(403): threadid=1: thread exiting with uncaught exception (group=0x40015560)

Android: how to refer to EditText view

I have the following layout:
<TextView
android:id = "#+id/HRNoninTextBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/exitbtn"
android:text="Heart Rate"
android:textSize = "20sp"/>
<EditText
android:id="#+id/labelNoninHeartRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:layout_alignParentRight="true">
</EditText>
from the code i refer to these views, form my activity, in this way:
TextView tvHr= (TextView)findViewById(R.id.HRNoninTextBox);
EditText etHr = (EditText)findViewById(R.id.labelNoninHeartRate);
the first one does not produce any error, while the second statement produce the following error:
01-09 13:24:57.599: W/dalvikvm(28816): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
01-09 13:24:57.619: E/AndroidRuntime(28816): FATAL EXCEPTION: main
01-09 13:24:57.619: E/AndroidRuntime(28816): java.lang.RuntimeException: Unable to start activity ComponentInfo{aid.assistant233/aid.assistant233.AidAssistant233Activity}: java.lang.ClassCastException: android.widget.TextView
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.os.Looper.loop(Looper.java:130)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.main(ActivityThread.java:3691)
01-09 13:24:57.619: E/AndroidRuntime(28816): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 13:24:57.619: E/AndroidRuntime(28816): at java.lang.reflect.Method.invoke(Method.java:507)
01-09 13:24:57.619: E/AndroidRuntime(28816): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
01-09 13:24:57.619: E/AndroidRuntime(28816): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
01-09 13:24:57.619: E/AndroidRuntime(28816): at dalvik.system.NativeStart.main(Native Method)
01-09 13:24:57.619: E/AndroidRuntime(28816): Caused by: java.lang.ClassCastException: android.widget.TextView
01-09 13:24:57.619: E/AndroidRuntime(28816): at aid.assistant233.AidAssistant233Activity.onCreate(AidAssistant233Activity.java:331)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-09 13:24:57.619: E/AndroidRuntime(28816): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-09 13:24:57.619: E/AndroidRuntime(28816): ... 11 more
Where may be the problem?
Step1 : you can clean/build your project as everyone said . but If you are not getting your issue solve by clean/build then check my step2 for it.
Step:2:
I am not Sure But Can you please check your xml file once again?
this also could be happen if You've two elements with the same ID:
<TextView android:text="Hello Ahmedabad:"
android:id="#+id/txtahmedabad"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/txtahmedabad"
android:text="">
</EditText>
if this is so then Give them different IDs -
it could picking the first one (the TextView) which obviously can't be cast to an EditText.
Hope it will some how help you.

Webview inside a TabView crashes when showing a dialog screen

I have a WebView in a TabView. The webView has a button. When the button is pressed a spinner is opened.
I am just loadng the webview with the URL. The action listener and spinner is triggered from the server side.
webview = (WebView) findViewById(R.id.webview);
....
....
webview.loadUrl(locationUrl);
My App is developed on Android 2.2. It is working fine in a device with OS 2.2 but crashing in 2.3.
Below is the log
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#406e21e0 is not valid; is your activity running?
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.view.ViewRoot.setView(ViewRoot.java:527)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.app.Dialog.show(Dialog.java:241)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.webkit.WebView$InvokeListBox.run(WebView.java:7583)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.os.Handler.handleCallback(Handler.java:587)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.os.Looper.loop(Looper.java:130)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684):     at dalvik.system.NativeStart.main(Native Method)
Use getparent() to get the parent context. As this is a tab, everything is done in parent context.

App crashes on selecting Spinner in a website openend in a WebView within the App

I have a WebView in one of the tabs in TabView. The webView loads a specific url which contains a spinner. The action listener and spinner is triggered from the server side embedded in the url.
webview = (WebView) findViewById(R.id.webview);
....
....
webview.loadUrl(locationUrl);
My App is developed on Android 2.2. It is working fine in a device with OS 2.2 but When I click the Spinner my app is crashing in a device with OS 2.3.
Below is the log
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#406e21e0 is not valid; is your activity running?
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.ViewRoot.setView(ViewRoot.java:527)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.Dialog.show(Dialog.java:241)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.webkit.WebView$InvokeListBox.run(WebView.java:7583)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.handleCallback(Handler.java:587)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.os.Looper.loop(Looper.java:130)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at java.lang.reflect.Method.invoke(Method.java:507)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-24 13:44:24.878: ERROR/AndroidRuntime(2684): at dalvik.system.NativeStart.main(Native Method)

Android webdav Java Sardine

im trying Sardine to make a webdav client in android, im trying this code:
This works perfect on JAVA aplicacion, but crashes in android :(
HttpClient client = new DefaultHttpClient();
SardineImpl sardine = new SardineImpl((AbstractHttpClient) client,"testuser","test");
List<DavResource> resources = sardine.getResources("http://demo.sabredav.org/");
for (int i = 1; i < resources.size(); i++) {
System.out.println(resources.get(i));
}
Replacing System.out.println by Toast i get this
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): java.lang.NoSuchMethodError: org.apache.http.impl.client.AbstractHttpClient.setRedirectStrategy
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.init(SardineImpl.java:188)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.<init>(SardineImpl.java:182)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at es.sardine.sardine.onCreate(sardine.java:39)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Looper.loop(Looper.java:143)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.main(ActivityThread.java:4914)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at dalvik.system.NativeStart.main(Native Method)
I had the same trouble trying to use Sardine and including Apache HttpClient which would conflict with the version embedded in Android. So I decided to replace it with OkHttp and I have much less trouble.
Here is the fork I created: https://github.com/thegrizzlylabs/sardine-android
Did you see this q: Using webdav on Android ? It essentially says that Sardine needs newer HttpClient version than packages with Android, and provides a lick to patched HttpClient 4.1 linkable into Android apps.
For you only iterating through the elements on the server this code worked for me:
try{
Sardine sardine = SardineFactory.begin("username", "password");
List<DavResource> resources = sardine.list("webdav/server/directory/");
buffer = new StringBuilder();
for (DavResource res : resources)
{
//for example
buffer.append(res.toString());
}
}catch(Exception e){
Log.e("VIEWER" , e.getMessage());
}
I used the Sardine-Android Project Library in combination with the simpleframework.xml.

Categories

Resources