2017-01-01 97 views
0

我的Android應用程序有問題。它之前工作正常,但它開始後立即崩潰沒有任何錯誤,我不明白爲什麼。我在我的類中評論了(//)很多代碼,並且只留下了重要的工作內容,但仍然是同樣的問題。我有一個mainActivity和2個片段。Android應用程序在啓動後崩潰沒有任何錯誤

My project hiearchy

當我創建它自動創建文件夾的佈局片段,並把java類存在。 片段Java類(列表,集):

public class List extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_list, container, false); 
    } 
} 

主要業務類:

public class MainActivity extends AppCompatActivity { 

    /** 
    * The {@link android.support.v4.view.PagerAdapter} that will provide 
    * fragments for each of the sections. We use a 
    * {@link FragmentPagerAdapter} derivative, which will keep every 
    * loaded fragment in memory. If this becomes too memory intensive, it 
    * may be best to switch to a 
    * {@link android.support.v4.app.FragmentStatePagerAdapter}. 
    */ 
    private SectionsPagerAdapter mSectionsPagerAdapter; 

    /** 
    * The {@link ViewPager} that will host the section contents. 
    */ 
    private ViewPager mViewPager; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     // Create the adapter that will return a fragment for each of the three 
     // primary sections of the activity. 
     mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 

     // Set up the ViewPager with the sections adapter. 
     mViewPager = (ViewPager) findViewById(R.id.container); 
     mViewPager.setAdapter(mSectionsPagerAdapter); 

     TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 
     tabLayout.setupWithViewPager(mViewPager); 

     FloatingActionButton addButton = (FloatingActionButton) findViewById(R.id.add); 
     addButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 

    } 

    /** 
    * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
    * one of the sections/tabs/pages. 
    */ 
    public class SectionsPagerAdapter extends FragmentPagerAdapter { 

     SectionsPagerAdapter(FragmentManager fm) { 
      super(fm); 
     } 

     @Override 
     public Fragment getItem(int position) { 
      switch(position) { 
       case 0: 
        return new Set(); 
       case 1: 
        return new List(); 
       default: 
        return null; 
      } 
     } 

     @Override 
     public int getCount() { 
      // Show 3 total pages. 
      return 2; 
     } 

     @Override 
     public CharSequence getPageTitle(int position) { 
      switch (position) { 
       case 0: 
        return "ZADÁVÁNÍ"; 
       case 1: 
        return "SEZNAM"; 
      } 
      return null; 
     } 
    } 
} 

activity_main.xml中(產生的自動):

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="cz.sudoman281.kubirovacikalkulacka.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

</android.support.design.widget.CoordinatorLayout> 

片段.xml文件:

<FrameLayout 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" 
    tools:context=".layout.List"> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:text="List" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView6" /> 

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </GridLayout> 
</FrameLayout> 
+1

使用LogCat檢查與您的崩潰相關的Java堆棧跟蹤:https://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this – CommonsWare

+0

嘗試返回' 1'而不是'2' –

+0

@CommonsWare我只得到這個:http://pastebin.com/HTKwnH3D – sudoman281

回答

1

的logcat的當應用程序啓動時,過濾器並不總是顯示日誌。整合圖書館時,我遇到了類似的問題。這就是我如何找到問題所在。

在調試模式下啓動應用程序,在onCreate方法的第一行設置一個斷點並繼續前進(F8),直到出現崩潰。

1

從你的日誌輸出,我看到這行:

01-01 15:01:58.206 7457-7457/cz.sudoman281.kubirovacikalkulacka W /系統:ClassLoader的引用未知的路徑: /數據/應用/ cz.sudoman281.kubirovacikalkulacka-1/lib目錄/ arm64

我想有什麼不對您的本機庫,仔細檢查您撥打或CMake的打造專業化文件,請確保你正確加載您的本機庫從Java類。

如果你在與Android牛軋糖的設備/模擬器中運行你的應用程序的另一件事,你可能需要檢查您的本機庫不鏈接對非NDK庫如下所述:https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

+0

謝謝你的回答:)我不確定Make和CMake是什麼:/這是我的build.gradle:http://pastebin.com/vaQ4baYZ。我正在運行Android 6. – sudoman281

+0

我不確定,嘗試將編譯SDK和構建工具版本減少到24,看看會發生什麼。 –

相關問題