android.view.InflateException导致应用立即崩溃

时间:2019-05-21 22:07:36

标签: java android

我正在尝试运行一个与我的主要活动一起运行的片段。它指出我的片段导致膨胀异常。

在其他人针对类似问题的解决方案之后,我摆脱了fragment标签,并尝试将其其余部分插入线性布局标签中,但这导致该片段根本无法运行。我还尝试了从此处Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment捕获错误的代码,该代码也无法正常工作。

任何建议将不胜感激,在此先感谢您。

<fragment
        android:layout_width="fill_parent"
        android:name="com.example.textwatcherseparated.SpellingsClient"
        android:id="@+id/SpellingsClient"
        android:layout_height="fill_parent"
        android:tag="fragment_tag"/>

上面是第9行,它说错误来自哪里。 (具体来说,片段在第9行)

public class SpellingsClient extends Fragment implements 
SpellCheckerSessionListener {
  private static final String TAG = SpellingsClient.class.getSimpleName();
  private static final int NOT_A_LENGTH = -1;
  private TextView mMainView;
  private SpellCheckerSession mScs;
  @Override
 public void onCreate(Bundle savedInstanceState) {
    Log.i("TAG3333333", "Hi! I'm running!! " );
    super.onCreate(savedInstanceState);
    }

这是有问题的片段,我认为我的错误将在于onCreate或第9行,尽管也有可能稍后在SpellingsClient中出现。老实说,我不知道。

这也是我主要活动的一部分。它是独立运行的,所以我认为问题不在于此,只是以防万一:

public class MainActivity extends AppCompatActivity {

final static int RED_COLOR = Color.parseColor("#fb7373");
final static int GREEN_COLOR = Color.parseColor("#40de83");
@Override
protected void onCreate(Bundle savedInstanceState) {
     Log.i("TAG0000", "Hi! I'm running!! " );
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EditText editText = findViewById(R.id.editText);
    final TextView tvBeforeText = findViewById(R.id.tvBeforeText);
    final TextView tvBeforeNumbers = findViewById(R.id.tvBeforeNumbers);
    final TextView tvAfterText = findViewById(R.id.tvAfterText);
    final TextView tvAfterNumbers = findViewById(R.id.tvAfterNumbers);
    editText.addTextChangedListener(new TextWatcher() {

这是错误代码:

2019-05-21 14:45:38.130 15683-15683/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.textwatcherseparated, PID: 15683
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.textwatcherseparated/com.example.textwatcherseparated.MainActivity}: android.view.InflateException: Binary XML file line #9 in com.example.textwatcherseparated:layout/activity_main: Binary XML file line #9 in com.example.textwatcherseparated:layout/activity_main: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:81)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1935)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7116)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
 Caused by: android.view.InflateException: Binary XML file line #9 in com.example.textwatcherseparated:layout/activity_main: Binary XML file line #9 in com.example.textwatcherseparated:layout/activity_main: Error inflating class fragment
 Caused by: android.view.InflateException: Binary XML file line #9 in com.example.textwatcherseparated:layout/activity_main: Error inflating class fragment
 Caused by: java.lang.IllegalStateException: Fragment com.example.textwatcherseparated.SpellingsClient did not create a view.
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3778)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
    at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1084)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1012)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:976)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1138)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1099)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:697)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:549)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.example.textwatcherseparated.MainActivity.onCreate(MainActivity.java:25)
    at android.app.Activity.performCreate(Activity.java:7698)
    at android.app.Activity.performCreate(Activity.java:7687)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3096)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:81)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1935)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7116)
    at java.lang.reflect.Method.invoke(Native Method)

0 个答案:

没有答案