how to add username and password in http request to call web service? I have write REST web service and if user want to do request ,he neeed to request like this in terminal :
curl -u username:password http://localhost:8080/user/folder
httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1),
new UsernamePasswordCredentials("kyaw", "password"));
get.setHeader("Authorization","Basic a31hdzpwYXNzd29yZA==");
I used either way to do in android but get exception :
05-20 07:13:30.900: DEBUG/AndroidRuntime(557): Shutting down VM
05-20 07:13:30.900: WARN/dalvikvm(557): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-20 07:13:30.972: ERROR/AndroidRuntime(557): FATAL EXCEPTION: main
05-20 07:13:30.972: ERROR/AndroidRuntime(557): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.put}: java.lang.RuntimeException: Binary XML file line #18: You must supply a layout_width attribute.
05-20 07:13:30.972: ERROR/AndroidRuntime(557): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-20 07:13:30.972: ERROR/AndroidRuntime(557): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
How do i do?
The error is "You must supply a layout_width attribute" (copy pasted from your stack trace).
The error is unrelated to the code you are showing. You are missing a layout_width="" attribute in one of your components XML declaration.
Related
I'd like to create an account in my Android app programatically.
I've read thing about the AccountManager class and tried to implement it.
Unfortunately, I get a SecurityException when I try to add the account.
Account account = new Account(user.getLogin(), 'packageName');
The thing I don't understand is about the type (in the second parameter).
What do I've to put in second parameter in order to make my code working.
Moreover, I'd like to know if I can add an acount simply with theses lines of code, or should I use a service like many example show ?
Thanks
EDIT - Full Exception Message
java.lang.SecurityException: caller uid 10047 is different than the authenticator's uid
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.accounts.IAccountManager$Stub$Proxy.addAccount(IAccountManager.java:580)
at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:565)
at fr.opendev.elisaG.activity.LoginActivity.isUserAuthorized(LoginActivity.java:113)
at fr.opendev.elisaG.activity.LoginActivity.access$500(LoginActivity.java:27)
at fr.opendev.elisaG.activity.LoginActivity$1.onClick(LoginActivity.java:70)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16964)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
I am getting the signal strength from the wifi locations available. When I run the program, i get the output. But, when I click on refresh button, I get the error, as mentioned in the stack trace.
I know that before I kept the counter buttons, it was working perfectly, but after I kept the buttons for plus and minus, I am getting the error, only when i click on refresh button.
Can you please help me out.
Stack Trace :
FATAL EXCEPTION: main
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS flg=0x10000010 } in com.example.wifisignalstrength.MainActivity$1#410f98f8
android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
android.os.Handler.handleCallback(Handler.java:605)
android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4517)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
dalvik.system.NativeStart.main(Native Method)
03-06 13:15:45.102: E/AndroidRuntime(7139): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
java.util.ArrayList.get(ArrayList.java:304)
com.example.wifisignalstrength.MainActivity$1.onReceive(MainActivity.java:202)
android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
Take a look on the count==15 branch. You are trying to get first element (index = 0) of empty ArrayList, since you've only initialized it via ArrayList<String> arr = new ArrayList<String>();, but it has no data. The only place where you put data to it is count<15 && count>=5 branch.
I am new to Android ,
I followed the instructions on the link http://marakana.com/forums/android/examples/49.html to create the basic application using NDK.
I followed those steps exactly. I also created the shared library.
When I run the application, CatLog shows the following errors:
Trying to load lib /data/data/com.example.NDKDemo/lib/libndk_demo.so 0x4129dc18
01-30 04:50:58.856: D/dalvikvm(586): Added shared lib
/data/data/com.example.NDKDemo/lib/libndk_demo.so 0x4129dc18
01-30 04:50:58.856: D/dalvikvm(586): No JNI_OnLoad found in
/data/data/com.example.NDKDemo/lib/libndk_demo.so 0x4129dc18,
skipping init
01-30 04:50:58.866: D/AndroidRuntime(586): Shutting down VM
01-30 04:50:58.866: W/dalvikvm(586): threadid=1: thread exiting with uncaught
exception (group=0x409c01f8)
01-30 04:50:58.896: E/AndroidRuntime(586): FATAL EXCEPTION: main
01-30 04:50:58.896: E/AndroidRuntime(586): java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo
{com.example.NDKDemo/com.example.NDKDemo.NativeLib}:
java.lang.ClassCastException:
com.example.NDKDemo.NativeLib cannot be cast to android.app.Activity
As mentioned, JNI_OnLoad isn't necessary. Here's your problem:
Unable to instantiate activity ComponentInfo
{com.example.NDKDemo/com.example.NDKDemo.NativeLib}:
java.lang.ClassCastException:
com.example.NDKDemo.NativeLib cannot be cast to android.app.Activity
Your bug isn't even an NDK issue, it looks like: Your class com.example.NDKDemo.NativeLib can't be cast to android.app.Activity.
The class you list in AndroidManifest.xml is the one that derives from Activity. If you created an NDKDemo class like in the example, then that's your activity, and you should name it in AndroidManifest.xml:
<activity android:name="NDKDemo" ... other options ... >
I'm seeing this exception in my android Market Developer Console -->Crash errors
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:398)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:366)
at android.widget.AbsListView.obtainView(AbsListView.java:1943)
at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1143)
at android.widget.ListView.makeAndAddView(ListView.java:1756)
at android.widget.ListView.fillDown(ListView.java:656)
at android.widget.ListView.fillSpecific(ListView.java:1314)
at android.widget.ListView.layoutChildren(ListView.java:1587)
at android.widget.AbsListView.onLayout(AbsListView.java:1794)
at android.view.View.layout(View.java:9330)
at android.view.ViewGroup.layout(ViewGroup.java:3795)
at android.widget.FrameLayout.onLayout(FrameLayout.java:400)
at android.view.View.layout(View.java:9330)
at android.view.ViewGroup.layout(ViewGroup.java:3795)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1201)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1944)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3998)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Here are the things which i don't understand about this error:
Where is it coming from (i don't see any reference to my classes in this trace)?
Does it mean the application shuts down because of this errors?
What is the mechanism by which this error gets logged in market place?
Note : there are no user messages in the error log.
Looks like either it expects a TextView in your layout which is not there, or an item in your list is null. The relevant source is at http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.5_r1/android/widget/ArrayAdapter.java#ArrayAdapter.createViewFromResource%28int%2Candroid.view.View%2Candroid.view.ViewGroup%2Cint%29, line 398 corresponds to line 355 on this page.
I am trying to parse the xml data coming from webservice using SAX parser, when i try to parse the data(size:7.4MB) using URL, it works fine but when I copy the xml data from the URL and place the xml file(size:7.4MB) in the raw folder, the parsing fails.
When the size of file placed in raw folder is reduced to 1.95MB, it works fine. I have tried shuffling the tags to check if there are any issues with the data, I haven't found any.It works fine as long as the size doesn't exceed 1.95MB. Is there any size limit while parsing the data from raw folder in android? if yes what is the limit? or How to parse the large files using SAX parser?
Any pointers will really help me. Thanks in advance for your time and any help offered.
Regards,
Ramesh
02-14 17:35:35.651: DEBUG/asset(11035): Data exceeds UNCOMPRESS_DATA_MAX (2138421 vs 2097152)
02-14 17:35:35.651: WARN/dalvikvm(11035): threadid=9: thread exiting with uncaught exception (group=0x4001d7d0)
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): FATAL EXCEPTION: Thread-13
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): java.lang.AssertionError: java.io.IOException
02-14 17:35:35.659: ERROR/AndroidRuntime(11035): at android.util.Xml.parse(Xml.java:89)
code
try {
System.out.println("1");
//Xml.parse((url.openConnection().getInputStream()), Encoding.UTF_8, datahandler);
Xml.parse(getResources().openRawResource(R.raw.sample), Encoding.UTF_8, datahandler);
System.out.println("2");
//xr.parse(new InputSource(getAssets().open("sample.xml")));
}catch(Exception e){
System.out.println("Ramesh"+"XML Parsing exception:"+e);
}
error
Android DEBUG/asset(11035): Data exceeds UNCOMPRESS_DATA_MAX (2138421 vs 2097152)
WARN/dalvikvm(11035): threadid=9: thread exiting with uncaught exception (group=0x4001d7d0)
ERROR/AndroidRuntime(11035): FATAL EXCEPTION: Thread-13
ERROR/AndroidRuntime(11035): java.lang.AssertionError: java.io.IOException
ERROR/AndroidRuntime(11035): at android.util.Xml.parse(Xml.java:89)
ERROR/AndroidRuntime(11035): at com.infosys.gss.ui.Login$2$1.run(Login.java:431)
ERROR/AndroidRuntime(11035): Caused by: java.io.IOException