我无法复制它但是我看到这个视图注入崩溃通过Crashlytics影响了大约5-10%的用户。
该应用程序在我投入的所有内容上都能正常运行,但有些用户肯定没有这种体验。
我错过了什么?为什么会在某些设备上发生这种情况,而不是在同一型号的其他设备上发生?
受影响的设备包括Nexus 4和Nexus 5.我在两者上都尝试过(Nexus 4是我的主要设备)没有任何问题。受影响的还有几个三星。
有什么想法吗?
这是完整的堆栈跟踪,然后是愚蠢的简单类和布局xml:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.app/com.package.app.WelcomeActivity}: java.lang.RuntimeException: Unable to inject views for com.package.app.WelcomeActivity@42b210a8
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.RuntimeException: Unable to inject views for com.package.app.WelcomeActivity@42b210a8
at butterknife.ButterKnife.inject(ButterKnife.java:263)
at butterknife.ButterKnife.inject(ButterKnife.java:165)
at com.package.app.WelcomeActivity.onCreate(WelcomeActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalStateException: Required view with id '2131296260' for field 'mButtonScores' was not found. If this view is optional add '@Optional' annotation.
at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:122)
at com.package.app.WelcomeActivity$$ViewInjector.inject(WelcomeActivity$$ViewInjector.java:12)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at butterknife.ButterKnife.inject(ButterKnife.java:254)
at butterknife.ButterKnife.inject(ButterKnife.java:165)
at com.package.app.WelcomeActivity.onCreate(WelcomeActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
public class WelcomeActivity extends FretsActivity {
private Context mContext;
@InjectView(R.id.buttonPlay) public Button mButtonPlay;
@InjectView(R.id.buttonScores) public Button mButtonScores;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_welcome);
mContext = this;
ButterKnife.inject(this);
mButtonPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, MainActivity.class);
startActivity(intent);
}
});
mButtonScores.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, ScoreActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.welcome, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.package.app.screens.WelcomeActivity">
<ImageView
android:id="@+id/imageLogo"
android:src="@drawable/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:layout_width="140dp"
android:layout_height="80dp" />
<TextView
android:layout_centerHorizontal="true"
android:layout_below="@+id/imageLogo"
android:text="Play the Game"
android:fontFamily="sans-serif-thin"
android:layout_width="wrap_content"
android:textSize="36sp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonPlay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
style="@style/QuizButton"
android:text="@string/menu_play"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonScores"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/menu_scores"
style="@style/QuizButton"
android:layout_marginBottom="24dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:textSize="18sp"
android:paddingTop="@dimen/vertical_padding_half"
android:paddingBottom="@dimen/vertical_padding_half"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
答案 0 :(得分:0)
即使AndroidManifest禁止活动,也有办法强制活动进入纵向模式。我在您的应用中尝试了https://play.google.com/store/apps/details?id=com.googlecode.eyesfree.setorientation,并且您提到了例外情况。
因此,我建议您查看布局,可能是您忘记了以纵向模式加载并且不包含buttonScores
的activity_welcome.xml。