c语言 void actionl,当我按下按钮时,应用程序强制关闭

当我按下工具栏中的打印按钮时,我的应用程序关闭。我想我已将代码放在错误的地方?也许代码是错误的?还是其他什么东西......当我按下按钮时,应用程序强制关闭

MainActivity.java:

package com.vvhvb.hesselfeenstra.vvheerenveenseboys;

import android.content.Intent;

import android.os.Bundle;

import android.support.design.widget.FloatingActionButton;

import android.support.design.widget.Snackbar;

import android.support.v7.app.AppCompatActivity;

import android.support.v7.widget.Toolbar;

import android.view.View;

import android.view.Menu;

import android.view.MenuItem;

import android.webkit.WebView;

import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

String url ="http://dehvb.nl/";

WebView view=(WebView) this.findViewById(R.id.webView);

view.getSettings().setJavaScriptEnabled(true);

view.getSettings().setBuiltInZoomControls(true);

view.getSettings().setDisplayZoomControls(false);

view.loadUrl(url);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.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();

Button btnSimple = (Button) findViewById(R.id.action_about);

btnSimple.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(v.getContext(), about.class);

startActivityForResult(intent, 0);

}

});

//noinspection SimplifiableIfStatement

if (id == R.id.action_about) {

return true;

}

return super.onOptionsItemSelected(item);

}

}

about.java

package com.vvhvb.hesselfeenstra.vvheerenveenseboys;

import android.app.Activity;

import android.os.Bundle;

public class about extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.about);

}

}

的logcat:

06-12 11:53:10.441 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/WebViewFactory: Loading com.google.android.webview version 50.0.2661.86 (code 266108600)

06-12 11:53:10.441 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys W/ResourcesManager: getTopLevelResources: /data/app/com.google.android.webview-2/base.apk/1.0 running in com.vvhvb.hesselfeenstra.vvheerenveenseboys rsrc of package com.google.android.webview

06-12 11:53:10.451 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/ResourcesManager: For user 0 new overlays fetched Null

06-12 11:53:10.451 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/InjectionManager: Inside getClassLibPath caller

06-12 11:53:10.461 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 9936-9938)

06-12 11:53:10.461 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/cr_LibraryLoader: Expected native library version number "50.0.2661.86", actual native library version number "50.0.2661.86"

06-12 11:53:10.471 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {bde8c1c}

06-12 11:53:10.471 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/cr_LibraryLoader: Expected native library version number "50.0.2661.86", actual native library version number "50.0.2661.86"

06-12 11:53:10.471 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/chromium: [INFO:library_loader_hooks.cc(143)] Chromium logging enabled: level = 0, default verbosity = 0

06-12 11:53:10.501 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/cr_BrowserStartup: Initializing chromium process, singleProcess=true

06-12 11:53:10.511 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys E/ApkAssets: Error while loading asset assets/natives_blob_64.bin: java.io.FileNotFoundException: assets/natives_blob_64.bin

06-12 11:53:10.511 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys E/ApkAssets: Error while loading asset assets/snapshot_blob_64.bin: java.io.FileNotFoundException: assets/snapshot_blob_64.bin

06-12 11:53:10.521 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/libEGL: loaded /vendor/lib/egl/libGLES_mali.so

06-12 11:53:10.551 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/libEGL: eglInitialize EGLDisplay = 0xffccd144

06-12 11:53:10.611 15392-15527/com.vvhvb.hesselfeenstra.vvheerenveenseboys W/cr_media: Requires BLUETOOTH permission

06-12 11:53:10.631 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/art: Rejecting re-init on previously-failed class java.lang.Class

06-12 11:53:10.631 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/art: Rejecting re-init on previously-failed class java.lang.Class

06-12 11:53:10.681 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/art: Rejecting re-init on previously-failed class java.lang.Class

06-12 11:53:10.691 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/art: Rejecting re-init on previously-failed class java.lang.Class

06-12 11:53:10.711 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/cr_Ime: [InputMethodManagerWrapper.java:30] Constructor

06-12 11:53:10.731 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring

06-12 11:53:10.731 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: false

06-12 11:53:10.791 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/cr_Ime: ImeThread is not enabled.

06-12 11:53:10.801 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/Activity: performCreate Call Injection manager

06-12 11:53:10.801 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/InjectionManager: dispatchOnViewCreated > Target : com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity isFragment :false

06-12 11:53:10.811 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

06-12 11:53:10.811 15392-15572/com.vvhvb.hesselfeenstra.vvheerenveenseboys E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)

06-12 11:53:10.811 15392-15572/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/libEGL: eglInitialize EGLDisplay = 0xde341864

06-12 11:53:10.831 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null

06-12 11:53:10.831 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/PhoneWindow: *FMB* isFloatingMenuEnabled return false

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/libEGL: eglInitialize EGLDisplay = 0xde43fc54

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/OpenGLRenderer: Initialized EGL, version 1.4

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/OpenGLRenderer: HWUI protection enabled for context , &this =0xf4f12490 ,&mEglDisplay = 1 , &mEglConfig = -185306468

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/OpenGLRenderer: Get maximum texture size. GL_MAX_TEXTURE_SIZE is 8192

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/OpenGLRenderer: Enabling debug mode 0

06-12 11:53:10.891 15392-15571/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/mali_winsys: new_window_surface returns 0x3000, [1080x1920]-format:1

06-12 11:53:11.101 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/InjectionManager: dispatchCreateOptionsMenu :com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity

06-12 11:53:11.101 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/InjectionManager: dispatchPrepareOptionsMenu :com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity

06-12 11:53:11.271 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/Timeline: Timeline: Activity_idle id: [email protected] time:6070740

06-12 11:53:11.501 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 15392

06-12 11:53:11.511 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true

06-12 11:53:11.511 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow

06-12 11:53:16.391 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN

06-12 11:53:16.471 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/InjectionManager: dispatchOptionsItemSelected :com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity

06-12 11:53:16.481 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys D/AndroidRuntime: Shutting down VM

06-12 11:53:16.481 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.vvhvb.hesselfeenstra.vvheerenveenseboys, PID: 15392

java.lang.ClassCastException: android.support.v7.view.menu.ActionMenuItemView cannot be cast to android.widget.Button

at com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity.onOptionsItemSelected(MainActivity.java:48)

at android.app.Activity.onMenuItemSelected(Activity.java:3201)

at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:403)

at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:189)

at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)

at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)

at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)

at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:169)

at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:760)

at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)

at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)

at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)

at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)

at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)

at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)

at android.view.View.performClick(View.java:5246)

at android.widget.TextView.performClick(TextView.java:10604)

at android.view.View$PerformClick.run(View.java:21256)

at android.os.Handler.handleCallback(Handler.java:739)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:145)

at android.app.ActivityThread.main(ActivityThread.java:6917)

at java.lang.reflect.Method.invoke(Native Method)

at java.lang.reflect.Method.invoke(Method.java:372)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

06-12 11:53:19.991 15392-15392/com.vvhvb.hesselfeenstra.vvheerenveenseboys I/Process: Sending signal. PID: 15392 SIG: 9

about.xml

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent">

activity_main.xml中

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

tools:context="com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary"

app:popupTheme="@style/AppTheme.PopupOverlay" />

content_main.xml

xmlns:app="http://schemas.android.com/apk/res-auto"

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"

app:layout_behavior="@string/appbar_scrolling_view_behavior"

tools:context="com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity"

tools:showIn="@layout/activity_main">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/webView"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

我希望有人能帮助我解决这个问题。

2016-06-12

Hessel

+1

什么样的视图具有ID“action_about”?请显示XML。 –

+0

在主菜单.xlm文件中还是在主布局文件中是此action_about按钮? –

+0

此按钮位于menu_main中。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值