Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I need to access stringarray present in res/values/string.xml to Activity class. Below shown is my code
- package com.string;
- import android.app.Activity;
- import android.os.Bundle;
- public class FirstAct extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- String arr[] = getResources().getStringArray(R.array.planet);
- for (int i = 0; i < arr.length; i++) {
- System.out.println(arr[i]);
- }
- }
- }
- string.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, FirstAct!</string>
- <string name="app_name">string</string>
- <string-array name="planet">
- <item>Mercury</item>
- <item>Venus</item>
- <item>Earth</item>
- </string-array>
- </resources>
- This is LogCat
- 08-28 08:16:59.166: DEBUG/AndroidRuntime(346): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
- 08-28 08:16:59.166: DEBUG/AndroidRuntime(346): CheckJNI is ON
- 08-28 08:16:59.306: DEBUG/AndroidRuntime(346): --- registering native functions ---
- 08-28 08:16:59.896: DEBUG/AndroidRuntime(346): Shutting down VM
- 08-28 08:16:59.896: DEBUG/dalvikvm(346): Debugger has detached; object registry had 1 entries
- 08-28 08:16:59.926: INFO/AndroidRuntime(346): NOTE: attach of thread 'Binder Thread #3' failed
- 08-28 08:17:00.426: DEBUG/AndroidRuntime(354): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
- 08-28 08:17:00.426: DEBUG/AndroidRuntime(354): CheckJNI is ON
- 08-28 08:17:00.566: DEBUG/AndroidRuntime(354): --- registering native functions ---
- 08-28 08:17:01.166: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.string/.FirstAct }
- 08-28 08:17:01.166: DEBUG/AndroidRuntime(354): Shutting down VM
- 08-28 08:17:01.176: DEBUG/dalvikvm(354): Debugger has detached; object registry had 1 entries
- 08-28 08:17:01.196: INFO/AndroidRuntime(354): NOTE: attach of thread 'Binder Thread #3' failed
- 08-28 08:21:23.466: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
- This is console
- [2011-08-28 08:16:59 - string] ------------------------------
- [2011-08-28 08:16:59 - string] Android Launch!
- [2011-08-28 08:16:59 - string] adb is running normally.
- [2011-08-28 08:16:59 - string] Performing com.string.FirstAct activity launch
- [2011-08-28 08:16:59 - string] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'rr'
- [2011-08-28 08:17:00 - string] Application already deployed. No need to reinstall.
- [2011-08-28 08:17:00 - string] Starting activity com.string.FirstAct on device emulator-5554
- [2011-08-28 08:17:02 - string] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.string/.FirstAct }
- [2011-08-28 08:17:02 - string] ActivityManager: Warning: Activity not started, its current task has been brought to the front
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement