Reputation: 163
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.ExchangeService$7.run(ExchangeService.java:1856)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
05-15 06:46:23.382: E/ActivityThread(555): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
05-15 06:46:23.382: E/ActivityThread(555): at android.os.AsyncTask$2.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
Upvotes: 0
Views: 83
Reputation: 23638
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;
}
}
Upvotes: 2
Reputation: 1020
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");
Upvotes: 0