Previously I have done some code with android using sdk 17, where the activity extended Activity. But yesterday I updated everything from my sdk manager. And first problem I was facing was that I couldn't build application with min sdk less then API-14. So, I used min sdk-14 and proceeded. When I gave button, textview etc in main_fragmet - the application was running. But the problem occurs when I am trying to give value in textview from code in mainActivity. Below is the code:
public class MainActivity extends Activity {
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t=(TextView)findViewById(R.id.txtvw);
t.setText("Shaonn");
//t.setText("Shaon");
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
in AVD its not running and error showin unfortunately the app has stoped.
Error from logcat:
05-15 06:46:21.812: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
05-15 06:46:23.382: E/ActivityThread(555): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd5418 that was originally bound here
05-15 06:46:23.382: E/ActivityThread(555): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd5418 that was originally bound here
05-15 06:46:23.382: E/ActivityThread(555): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
05-15 06:46:23.382: E/ActivityThread(555): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
05-15 06:46:23.382: E/ActivityThread(555): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
05-15 06:46:23.382: E/ActivityThread(555): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
05-15 06:46:23.382: E/ActivityThread(555): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.exchange.ExchangeService7ドル.run(ExchangeService.java:1856)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.utility.Utility2ドル.doInBackground(Utility.java:551)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.utility.Utility2ドル.doInBackground(Utility.java:549)
05-15 06:46:23.382: E/ActivityThread(555): at android.os.AsyncTask2ドル.call(AsyncTask.java:287)
05-15 06:46:23.382: E/ActivityThread(555): at java.util.concurrent.FutureTask.run (FutureTask.java:234)
05-15 06:46:23.382: E/ActivityThread(555): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-15 06:46:23.382: E/ActivityThread(555): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-15 06:46:23.382: E/ActivityThread(555): at java.lang.Thread.run(Thread.java:856)
05-15 06:46:23.412: E/StrictMode(555): null
-
3What error you are getting ?GrIsHu– GrIsHu2014年05月15日 06:45:04 +00:00Commented May 15, 2014 at 6:45
-
Do you've TextView placed in activity_main.xml or fragement...xml ? Post your logcat as said by @Gr.....Ramakishna Balla– Ramakishna Balla2014年05月15日 06:47:55 +00:00Commented May 15, 2014 at 6:47
-
Edited my question. And my TextView is in fragment.xmlshaon007– shaon0072014年05月15日 06:51:41 +00:00Commented May 15, 2014 at 6:51
-
If your textview in in fragment.xml file then you can not access your textview in mainactivity. I should be inside placefragment file.GrIsHu– GrIsHu2014年05月15日 06:53:36 +00:00Commented May 15, 2014 at 6:53
-
change your emulator settings to use lcd_density, try to run the same code on device.Lalith B– Lalith B2014年05月15日 06:57:59 +00:00Commented May 15, 2014 at 6:57
2 Answers 2
For error:
Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd5418 that was originally bound here
05-15 06:46:23.382: E/ActivityThread(555): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd5418 that was originally bound here
Try disabling host GPU in the Emulator options, it will fix the problem.
Also,
If your TextView in in fragment.xml file then you can not access your TextView in Mainactivity. I should be inside placefragment file.
public class PlaceholderFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment, container, false);
TextView t=(TextView) v.findViewById(R.id.txtvw);
t.setText("Shaonn");
return v;
}
}
1 Comment
That's the issue...You've your textview in frgament.xml but you are initializing it in activity_main.xml..remove the code from here
and Paste it in fragment
t=(TextView) rootView.findViewById(R.id.txtvw);
t.setText("Shaonn");