0

我知道有幾百億的關於RunTimeException的問題,當試圖開始活動,但我真的沒有找到我的問題的答案。RunTimeException當開始活動

logcat的

09-06 13:35:38.283: E/AndroidRuntime(14080): FATAL EXCEPTION: main 
09-06 13:35:38.283: E/AndroidRuntime(14080): Process: com.example.mylifeinformationsharedsocial, PID: 14080 
09-06 13:35:38.283: E/AndroidRuntime(14080): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mylifeinformationsharedsocial/com.example.mylifeinformationsharedsocial.LoginActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown> 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.ActivityThread.access$800(ActivityThread.java:148) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.os.Handler.dispatchMessage(Handler.java:102) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.os.Looper.loop(Looper.java:135) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.ActivityThread.main(ActivityThread.java:5274) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at java.lang.reflect.Method.invoke(Method.java:372) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909) 
09-06 13:35:38.283: E/AndroidRuntime(14080): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown> 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.createView(LayoutInflater.java:633) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at com.example.mylifeinformationsharedsocial.LoginActivity.onCreate(LoginActivity.java:15) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.Activity.performCreate(Activity.java:5977) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
09-06 13:35:38.283: E/AndroidRuntime(14080): ... 10 more 
09-06 13:35:38.283: E/AndroidRuntime(14080): Caused by: java.lang.reflect.InvocationTargetException 
09-06 13:35:38.283: E/AndroidRuntime(14080): at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
09-06 13:35:38.283: E/AndroidRuntime(14080): ... 24 more 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.content.res.TypedArray.getDrawable(TypedArray.java:749) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.View.<init>(View.java:3737) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.view.ViewGroup.<init>(ViewGroup.java:491) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.widget.LinearLayout.<init>(LinearLayout.java:196) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.widget.LinearLayout.<init>(LinearLayout.java:192) 
09-06 13:35:38.283: E/AndroidRuntime(14080): ... 27 more 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1091) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1017) 
09-06 13:35:38.283: E/AndroidRuntime(14080): at android.content.res.Resources.loadDrawableForCookie(Resources.java:2459) 
09-06 13:35:38.283: E/AndroidRuntime(14080): ... 34 more 

activity_login.xml:

<ScrollView 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.mylifeinformationsharedsocial.LoginActivity" > 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff"> 

    <!-- Header Starts--> 
    <LinearLayout 
     android:id="@+id/linear_layout_header_id" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@layout/header_gradient" 
     android:paddingTop="5dip" 
     android:paddingBottom="5dip"> 

      <!-- Logo Start--> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/hd_logo" 
       android:layout_marginLeft="10dip" 
       android:layout_marginStart="10dip" 
       android:contentDescription="@string/imgae_view_logo_content_description" 
       /> 

    </LinearLayout>   
      <!-- Logo Ends --> 
    <!-- Header Ends --> 

    <!-- Footer Start --> 
    <LinearLayout 
     android:id="@+id/linear_layout_footer_id" 
     android:layout_width="fill_parent" 
     android:layout_height="90dip" 
     android:orientation="vertical" 
     android:background="@layout/footer_repeat" 
     android:layout_alignParentBottom="true"> 
    </LinearLayout> 
    <!-- Footer Ends --> 

    <!-- Login Form --> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dip"> 
     <!-- Email Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#372c24" 
      android:text="Email" 
      /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dip" 
      android:layout_marginBottom="20dip" 
      android:singleLine="true" 
      /> 
     <!-- Password Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#372c24" 
      android:text="Password" 
      /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dip" 
      android:singleLine="true" 
      android:password="true" 
      /> 
     <!-- Login button --> 
     <Button 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dip" 
      android:text="Login" 
      /> 
     <!-- Link to Registration Screen --> 
     <TextView 
      android:id="@+id/link_to_register" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="40dip" 
      android:layout_marginBottom="40dip" 
      android:text="New to Twitter? Register here" 
      android:gravity="center" 
      android:textSize="20dip" 
      android:textColor="#0b84aa" 
      /> 

    </LinearLayout> 
    <!-- Login Form Ends --> 

    </RelativeLayout> 

</ScrollView> 

我不明白很多關於LogCat但它說android.view.InflateException: Binary XML file line #17: Error inflating class,就是指的在activity_login.xml文件或什麼?

MainActivity.java:

public class MainActivity extends AppCompatActivity 
{ 
TextView textView1; 

Button hairCutsButton; 
Button sexButton; 
Button signUpButton; 
Button loginButton; 



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

    textView1 = (TextView) findViewById(R.id.textView_1); 
    textView1.setTextColor(Color.rgb(0, 0, 0)); 

    hairCutsButton = (Button) findViewById(R.id.hairCutsButton_1); 
    sexButton = (Button) findViewById(R.id.sexButton_1); 
    signUpButton = (Button) findViewById(R.id.sign_up_button_id); 
    loginButton = (Button) findViewById(R.id.login_button_id); 

    signUpButton.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      Intent intent = new Intent(MainActivity.this,SignUpActivity.class); 
      startActivity(intent); 
     } 
    }); 
    loginButton.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      Intent intent = new Intent(MainActivity.this,LoginActivity.class); 
      startActivity(intent); 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) 
    { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public void moveToHairCutsActivity(View view) 
{ 
    Intent intent = new Intent(this,HairCutsActivity.class); 
    startActivity(intent); 
} 
public void moveToSexActivity(View view) 
{ 
    Intent intent = new Intent(this,SexAcivity.class); 
    startActivity(intent); 
} 

}

顯然,當

Intent intent = new Intent(MainActivity.this,LoginActivity.class); 
startActivity(intent); 

那些2線所執行的RunTimeException引起。

請幫幫我。

LognActivity.java:

public class LoginActivity extends AppCompatActivity 
{ 

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

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.login, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) 
    { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 
} 

header_gradient.xml:

<?xml version="1.0" encoding="utf-8"?> 
<Shape xmlns:android="http://schemas.android.com/apk/res/android" > 

<gradient 
    android:startColor="#24b2eb" 
    android:centerColor="#4ccbff" 
    android:endColor="#24b2eb" 
    android:angle="270" 
    /> 
<corners 
    android:radius="5dp" 
    /> 

</Shape> 

footer_repeat.xml:

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:tileMode="repeat" 
    /> 
+0

問題是'LoginActivity',所以顯示'LoginActivity'活動和佈局xml –

+0

@ρяσѕρєяK有佈局。我會添加活動。 – God

+0

@ρяσѕρєяK它基本上是空的。 – God

回答

1

在這裏:

<LinearLayout 
     android:id="@+id/linear_layout_header_id" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@layout/header_gradient" <<<<< line 
     android:paddingTop="5dip" 
     android:paddingBottom="5dip"> 
... 
</LinearLayout> 

目前從layout文件夾這是不正確的設置背景繪製。移動header_gradient文件夾drawable這是我們想要的任何view.then使用background使用可繪製,選擇和形狀合適的地方:

android:background="@drawable/header_gradient" 
+0

將它移動到drawable,但仍然在第17行獲得相同的LogCat。'android:background =「@ drawable/header_gradient」' – God

+0

@God:在android:id =「@ + id/linear_layout_footer_id」所以也以相同的方式更改'android:background =「@ layout/footer_repeat」' –

+0

我也改變了頁腳。還添加了header_gradient.xml文件。 – God