按钮单击意图崩溃应用程序

时间:2018-01-23 21:47:01

标签: java android

我有一个问题,

我无法按下按钮 点击它应该从MainActivity切换到Login 没有Button,这两个类都可以正常工作 但现在,当我带入Button时,它一直在崩溃。 我究竟做错了什么? 这个按钮,让我从登录到Mainactivity,工作得很好:

public class login extends Activity  {
Button b1,b2;
EditText ed1,ed2;

TextView tx1;
int counter = 3;

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

    b1 = (Button)findViewById(R.id.button);
    ed1 = (EditText)findViewById(R.id.editText);
    ed2 = (EditText)findViewById(R.id.editText2);

    b2 = (Button)findViewById(R.id.button2);
    tx1 = (TextView)findViewById(R.id.textView3);
    tx1.setVisibility(View.GONE);

    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(ed1.getText().toString().equals("admin") && ed2.getText().toString().equals("admin")) {
                Toast.makeText(getApplicationContext(),"Redirecting...",Toast.LENGTH_SHORT).show();
                        Intent i = new Intent(login.this, MainActivity.class);
                        startActivity(i);
            }
            else{
                Toast.makeText(getApplicationContext(), "Fehlerhafte Eingabe",Toast.LENGTH_SHORT).show();

                        tx1.setVisibility(View.VISIBLE);
                tx1.setBackgroundColor(Color.RED);
                counter--;
                tx1.setText(Integer.toString(counter));

                if (counter == 0) {
                    b1.setEnabled(false);
                }
            }
        }
    });

    b2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

}

按钮代码

 StrgS.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            {
                Toast.makeText(getApplicationContext(), "Goodbye", Toast.LENGTH_LONG).show();
                Intent j = new Intent(MainActivity.this, login.class);
                startActivity(j);
            }
        }
    });
}

}

错误代码

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.cris.zeiterfassungv2, PID: 10555
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cris.zeiterfassungv2/com.example.cris.zeiterfassungv2.MainActivity}: android.view.InflateException: Binary XML file line #0: Can't convert value at index 6 to dimension: type=0x12
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
               Caused by: android.view.InflateException: Binary XML file line #0: Can't convert value at index 6 to dimension: type=0x12
               Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 6 to dimension: type=0x12
                  at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:730)
                  at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7797)
                  at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1976)
                  at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1874)
                  at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1872)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                  at com.example.cris.zeiterfassungv2.MainActivity.onCreate(MainActivity.java:76)
                  at android.app.Activity.performCreate(Activity.java:6999)
                  at android.app.Activity.performCreate(Activity.java:6990)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

谢谢

0 个答案:

没有答案