0

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
asked May 15, 2014 at 6:43
6
  • 3
    What error you are getting ? Commented 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..... Commented May 15, 2014 at 6:47
  • Edited my question. And my TextView is in fragment.xml Commented 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. Commented May 15, 2014 at 6:53
  • change your emulator settings to use lcd_density, try to run the same code on device. Commented May 15, 2014 at 6:57

2 Answers 2

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;
 }
 }
answered May 15, 2014 at 7:03
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Really helped me. Can you please give another solution to this question: stackoverflow.com/questions/23647513/…
0

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");
answered May 15, 2014 at 6:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.