android-support-v7-appcompatを使用してアンドロイドアプリを開発しました。 Eclipseとうまくいきました。今日私はSDKを利用できる最新のバージョンに更新しました。すべて正常に動作しますが、アプリケーションの起動時にこのエラーが発生します。私のsdkを更新した後、android.view.InflateExceptionでアプリがクラッシュする:バイナリXMLファイルの行#36:クラスを膨張させるエラー。android.support.v7.widget.Toolbar
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.loan.collector/com.loan.collector.HomeActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.loan.collector.HomeActivity.onCreate(HomeActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 24 more
Caused by: java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.Toolbar_theme
at android.support.v7.widget.Toolbar.themifyContext(Toolbar.java:2007)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:195)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:191)
... 27 more
そして、これがHomeActivity.java
package com.loan.collector;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import com.loan.collector.addapter.TabsPagerAdapter;
import com.loan.collector.addapter.UserAdapter;
import com.loan.collector.utill.DatabaseHandler;
@SuppressWarnings("deprecation")
public class HomeActivity extends ActionBarActivity implements
ActionBar.TabListener{
Context context = this;
DatabaseHandler database = new DatabaseHandler(context);
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
public String[] tabs1 = { "SIGN IN", "SIGN UP"};
public String[] tabs2 = {"SIGN IN"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
getSupportActionBar().setDisplayShowHomeEnabled(false); // hides action bar icon
getSupportActionBar().setDisplayShowTitleEnabled(false);
exportDB();
ArrayList<UserAdapter> userList = database.getLoginUsers();
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bar_bg));
// Adding Tabs
if(userList.size()==1){
for (String tab_name : tabs1) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
mAdapter = new TabsPagerAdapter(getSupportFragmentManager(),2);
viewPager.setAdapter(mAdapter);
}else{
for (String tab_name : tabs2) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
mAdapter = new TabsPagerAdapter(getSupportFragmentManager(),1);
viewPager.setAdapter(mAdapter);
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
private void exportDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
// String currentDBPath =
// getApplicationContext().getDatabasePath("SalesPlayLiteDB");
// String backupDBPath =
// Environment.getExternalStorageDirectory().getPath()+"/Download";
File currentDB = getApplicationContext().getDatabasePath(
"CollectorDB");
File backupDB = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"CollectorDB_backup.db");
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
/*
* Toast.makeText(getApplicationContext(), "Backup Successful!",
* Toast.LENGTH_SHORT).show();
*/
}
} catch (Exception e) {
/*
* Toast.makeText(getApplicationContext(), "Backup Failed!",
* Toast.LENGTH_SHORT).show();
*/
e.printStackTrace();
}
}
@Override
public void onTabReselected(android.support.v7.app.ActionBar.Tab arg0,
android.support.v4.app.FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(android.support.v7.app.ActionBar.Tab tab,
android.support.v4.app.FragmentTransaction arg1) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(android.support.v7.app.ActionBar.Tab arg0,
android.support.v4.app.FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
}
activity_home.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/action_bar_color"
android:theme="@style/AppTheme" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/headerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigation Drawer Demo"
android:textColor="@color/action_bar_text_color" />
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="1/1"
android:visibility="gone"
android:textColor="@color/action_bar_text_color" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
でこのエラーを修正する方法を教えてください、ありがとう
HomeActivity.javaにすぎ – USKMobility
を追加してくださいあまりにも – USKMobility
をactivity_home.xmlファイルを追加してくださいすでにactivity_home.xmlとtoolbar.xml.thanks – cwgi