我测试了一个新的布局,当从MainActivity点击一个按钮时,我需要显示一个新的布局。我已经用Google搜索并尝试了每一个答案,然而,每一段代码都会导致应用程序崩溃。目前,我遇到了无法解析符号view
的问题。
有什么想法?非常感谢您的帮助。这是我的代码:
package com.example.consumer.example;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.next);
button.setOnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
};
};
}
}
我的崩溃日志如下(来自Logcat):
01-09 21:40:40.787 7001-7001/? E/android.os.Debug: failed to load memtrack module: -2
01-09 21:40:40.847 7006-7006/? E/memtrack: Couldn't load memtrack module (No such file or directory)
01-09 21:40:40.847 7006-7006/? E/android.os.Debug: failed to load memtrack module: -2
01-09 21:40:41.196 7022-7022/? E/memtrack: Couldn't load memtrack module (No such file or directory)
01-09 21:40:41.196 7022-7022/? E/android.os.Debug: failed to load memtrack module: -2
01-09 21:41:04.597 6950-6965/? E/EGL_emulation: tid 6965: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
01-09 21:41:04.620 6950-6950/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.surrrge.consumer.surrrge, PID: 6950
java.lang.RuntimeException: Canvas: trying to draw too large(110327008bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
at android.view.View.getDrawableRenderNode(View.java:17314)
at android.view.View.drawBackground(View.java:17250)
at android.view.View.draw(View.java:17062)
at android.view.View.updateDisplayListIfDirty(View.java:16053)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.updateDisplayListIfDirty(View.java:16048)
at android.view.View.draw(View.java:16837)
at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
at android.view.View.draw(View.java:17074)
at com.android.internal.policy.DecorView.draw(DecorView.java:751)
at android.view.View.updateDisplayListIfDirty(View.java:16053)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:656)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:662)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:770)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2796)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2604)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2211)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
01-09 21:41:05.021 1519-4976/system_process E/EGL_emulation: tid 4976: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
01-09 21:41:05.421 1994-2204/com.android.launcher3 E/EGL_emulation: tid 2204: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
01-09 21:42:46.053 1519-1875/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 104)
01-09 21:42:46.059 1519-1875/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 108)
答案 0 :(得分:1)
您错过了新的OnClickListener
,它应该就像这个例子:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
});
答案 1 :(得分:0)
尝试这样,并在添加View.OnclickListner实现方法时创建public void Onclick方法并在其中使用您的意图,或者您可以像Ahmed所说的那样。
package com.example.consumer.example;
//您的导入
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.next);
button.setOnClickListener(this);
}
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
}
答案 2 :(得分:0)
尝试评论DisplayListCanvas.java中的所有内容,看看错误是否仍然存在。
答案 3 :(得分:0)