-1
I have an Fragment...class in which I am inflating an xml file. This Fragment is being called in Mainactivity...but when executed this error appears
java.lang.Runtimeexception: Unable to start Activity Componentinfo{com.br.comunicacao/com.br.comunicacao.Mainactivity}: android.view.Inflateexception: Binary XML file line #30: Binary XML file line #30: Error inflating class Fragment at android.app.Activitythread.performLaunchActivity(Activitythread.java:2434) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2494) at android.app.Activitythread.access$900(Activitythread.java:153) at android.app.Activitythread$H.handleMessage(Activitythread.java:1347) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5451) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:726) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:616) Caused by: android.view.Inflateexception: Binary XML file line #30: Binary XML file line #30: Error inflating class Fragment at android.view.Layoutinflater.inflate(Layoutinflater.java:539) at android.view.Layoutinflater.inflate(Layoutinflater.java:423) at android.view.Layoutinflater.inflate(Layoutinflater.java:374) at com.android.Internal.policy.Phonewindow.setContentView(Phonewindow.java:393) at android.app.Activity.setContentView(Activity.java:2215) at com.br.comunicacao.MainActivity.onCreate(Mainactivity.java:27) at android.app.Activity.performCreate(Activity.java:6323) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2387) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2494) at android.app.Activitythread.access$900(Activitythread.java:153) at android.app.Activitythread$H.handleMessage(Activitythread.java:1347) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5451) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:726) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:616)
This is my Fragment class code:
public class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup conteiner, Bundle saveInstanceState){
View view = inflater.inflate(R.layout.layout_frag_1, conteiner);
return null;
}
}
And this is Mainactivity’s:
public class MainActivity extends FragmentActivity {
FragmentManager fm = getSupportFragmentManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] lista = new String[]{"ALMOÇO","BEBIDAS","COMO ESTOU ME SENTINDO","FAMILIA"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,lista);
ListView lv = (ListView) findViewById(R.id.listView2);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> lv, View view, int position, long id) {
if (position == 1){
Fragment1 fragment1 = (Fragment1) fm.findFragmentById(R.id.fragment1);
}
}
});
}
I already tried this, but the same error occurs.
– Everton Alves
Tried with false, as third parameter of the inflate method?
– hugofsousa
I just saw here the null return when I returned the view worked. Thank you!
– Everton Alves