J'ai une erreur quelque chose son écrit comme vue android gonfler erreur d'exception dans le gonflement du fragment de classe et son pointage à la classe MainActivity.java, j'essaie de trouver mais toujours pas de chance, car il n'y a pas d'erreur dans le studio Android, mais l'erreur s'affiche lors de l'exécution dans un périphérique virtuel.Erreur de gonflement du fragment de classe, gonflerexception
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ai_agamcompaq.flexible.MainActivity">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.ai_agamcompaq.flexible.FragmentA"
android:id="@+id/fragment"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.ai_agamcompaq.flexible.FragmentB"
android:id="@+id/fragment2"
android:layout_below="@+id/fragment"
android:layout_alignStart="@+id/fragment"
android:layout_marginTop="39dp" />
</RelativeLayout>
MainActivity.java
import android.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity implements Communicator{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void respond(int i) {
FragmentManager manager=getFragmentManager();
FragmentB f2= (FragmentB) manager.findFragmentById(R.id.fragment2);
f2.changedata(i);
}
}
FragmentA.java
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class FragmentA extends Fragment implements
AdapterView.OnItemClickListener {
ListView list;
Communicator communicator;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
communicator=(Communicator)getActivity();
list= (ListView) getActivity().findViewById(R.id.listView);
ArrayAdapter adapter=ArrayAdapter.createFromResource(getActivity(),R.array.titles,android.R.layout.simple_list_item_1);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long id) {
communicator.respond(i);
}
FragmentB.java
import android.app.Fragment;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
public class FragmentB extends Fragment {
TextView text;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_b,container,false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
text=(TextView) getActivity().findViewById(R.id.textView);
}
public void changedata(int i){
Resources res=getResources();
String[] description=res.getStringArray(R.array.description);
text.setText(description[i]);
}
}
Communicator.java
public interface Communicator {
public void respond(int i);
}
fragment_b.xml
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:id="@+id/editText" />
</LinearLayout>
fragment_a.xml
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:id="@+id/listView" />
strings.xml
<resources>
<string name="app_name">flexible</string>
<string-array name="titles">
<item>one</item>
<item>two</item>
<item>three</item>
<item>four</item>
</string-array>
<string-array name="description">
<item>oneoneoneoneoneoneoneoneoneoneo</item>
<item>twotwotwotwotwotwotwotwotwotwo</item>
<item>threethreethreethreethreethreethr</item>
<item>fourfourfourfourfourfourfourfourfo</item>
</string-array>
</resources>
J'ai erreur quelque chose de son écrit comme vue androïde erreur d'exception se gonflent en gonfler le fragment de classe et son pointage sur MainActivity.java classe, j'essaie de trouver mais toujours pas de chance, car il n'y a pas d'erreur dans le studio Android, mais une erreur se produit lors de l'exécution dans un appareil virtuel. Essayez ceci de la manière suivante:
show logcat s'il vous plaît –
D'une part, vous ne gonflez pas et ne renvoyez pas votre layout dans 'onCreateView()' de 'FragmentA''. Nous aurions cependant besoin de voir la trace complète de la pile pour être certain de ce qu'est le problème actuel. –