2015-12-28 130 views
2

嗨,大家好,我已經看過帖子和問題,但沒有一個是我的問題,也沒有建議的解決方案已經解決了我的問題。 我寫了有一個註冊按鈕,應該帶我到另一個活動是在註冊活動登錄頁面代碼 如下Android應用程序崩潰時,我開始意圖

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/signup" android:id="@+id/singupText" android:onClick="signUp" android:textColor="#093ff2" android:textSize="20sp" android:textStyle="bold|italic" android:layout_marginBottom="50dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="#00ffffff" />

的XML的按鈕,在onclick方法我其中按鈕是主要活動是

public void signUp(View v){ 
    Intent i = new Intent(MainActivity.this, signup.class); 
    MainActivity.this.finish(); 
    startActivity(i); 
} 

我的日誌如下

12-28 22:37:53.533 29835-29835/com.example.alloush.pesticides E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.example.alloush.pesticides, PID: 29835 
                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alloush.pesticides/com.example.alloush.pesticides.signup}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350) 
                       at android.app.ActivityThread.access$800(ActivityThread.java:163) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:157) 
                       at android.app.ActivityThread.main(ActivityThread.java:5335) 
                       at java.lang.reflect.Method.invokeNative(Native Method) 
                       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(Native Method) 
                      Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> 
                       at android.view.LayoutInflater.createView(LayoutInflater.java:626) 
                       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) 
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) 
                       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:827) 
                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:751) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                       at com.example.alloush.pesticides.signup.onCreate(signup.java:20) 
                       at android.app.Activity.performCreate(Activity.java:5389) 
                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256) 
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)  
                       at android.app.ActivityThread.access$800(ActivityThread.java:163)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:157)  
                       at android.app.ActivityThread.main(ActivityThread.java:5335)  
                       at java.lang.reflect.Method.invokeNative(Native Method)  
                       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(Native Method)  
                      Caused by: java.lang.reflect.InvocationTargetException 
                       at java.lang.reflect.Constructor.constructNative(Native Method) 
                       at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                       at android.view.LayoutInflater.createView(LayoutInflater.java:600) 
                       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)  
                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)  
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)  
                       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:827)  
                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:751)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:498)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:398)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:354)  
                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)  
                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)  
                       at com.example.alloush.pesticides.signup.onCreate(signup.java:20)  
                       at android.app.Activity.performCreate(Activity.java:5389)  
                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)  
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)  
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)  
                       at android.app.ActivityThread.access$800(ActivityThread.java:163)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:157)  
                       at android.app.ActivityThread.main(ActivityThread.java:5335)  
                       at java.lang.reflect.Method.invokeNative(Native Method)  
                       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(Native Method)  
                      Caused by: java.lang.OutOfMemoryError 
                       at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
                       at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677) 
                       at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507) 
                       at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872) 
                       at android.content.res.Resources.loadDrawable(Resources.java:3054) 
                       at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                       at android.view.View.<init>(View.java:3694) 
                       at android.view.View.<init>(View.java:3624) 
                       at android.view.ViewGroup.<init>(ViewGroup.java:474) 
                       at android.widget.RelativeLayout.<init>(RelativeLayout.java:236) 
                       at java.lang.reflect.Constructor.constructNative(Native Method)  
                       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)  
                       at android.view.LayoutInflater.createView(LayoutInflater.java:600)  
                       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)  
                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)  
                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)  
                       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:827)  
                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:751)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:498)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:398)  
                       at android.view.LayoutInflater.inflate(LayoutInflater.java:354)  
                       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)  
                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)  
                       at com.example.alloush.pesticides.signup.onCreate(signup.java:20)  
                       at android.app.Activity.performCreate(Activity.java:5389)  
                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)  
                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2256)  
                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)  
                       at android.app.ActivityThread.access$800(ActivityThread.java:163)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:157)  
                       at android.app.ActivityThread.main(ActivityThread.java:5335)  
                       at java.lang.reflect.Method.invokeNative(Native Method)  
                       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(Native Method) 

我試圖獨立啓動singup intent來檢查它是否一切順利,它的工作完美...但是我試圖啓動另一個活動發生了同樣的事情發生了應用程序崩潰和錯誤和日誌... 任何建議我的情況 ?

+0

是你想在您的佈局非常大的圖像文件的某處? –

+0

你能分享整個佈局XML文件嗎? –

+0

請嘗試以下操作 - 在Android清單中做'android:largeheap = true'或者在開始意圖之前刪除結束 –

回答

1

如果在佈局中使用ImageView,請檢查drawable/background_main即根佈局的背景圖像 - 解碼位圖時虛擬機內存不足。縮小圖像尺寸。所以最好的辦法是減小它的大小或分辨率。

+0

謝謝先生,這解決了我的問題。當我刪除了其他XML佈局的背景時,它完美的工作,然後我減少了圖像尺寸,它完美的工作! –

0

最後調用完成方法。

public void signUp(View v){ 
    Intent i = new Intent(MainActivity.this, signup.class); 
    startActivity(i); 
    MainActivity.this.finish(); 
    // or just write 
    //finish(); 
} 
+0

謝謝你的關注,但是這行代碼並不包含這個問題......它的圖像尺寸是@oalpayli在他的回答中提到的 –

0

您的logCat顯示一些錯誤。

此錯誤表明您的註冊類不存在。你有沒有在清單文件中聲明你的活動,請遵循java命名規則來命名一個類文件 - >第一個字符是大寫字母。

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alloush.pesticides/com.example.alloush.pesticides.signup}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> 

註冊活動中第20行的錯誤。

at com.example.alloush.pesticides.signup.onCreate(signup.java:20) 

某種觀點誇大錯誤

at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 

這種膨脹的錯誤可能是由於XML文件

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> 
+0

Hello Ankush。在回答時請保持恭敬的語氣,不要光顧。沒有必要從像「嘿,夥伴,你知道如何閱讀這個?」這樣的短語開始。此外,雖然此答案可能解釋錯誤,但它不提供解決方案。如果您需要它來查找確切的問題並解決問題,請向OP詢問更多信息。乾杯! – NSNoob

+1

你好Ankush,問題不在這裏,因爲其他佈局工作完美時,我做了一個啓動活動,這意味着問題是在膨脹另一個佈局除了XML文件和所有的Java文件是完美的錯誤或編譯器將不允許應用程序運行或構建。虛擬機在嘗試處理大尺寸圖像尺寸時耗盡內存,例如1200x1600,因此我將其轉換爲800x600並完美運行... –