android 7.0点击中间的哪个按钮后显示所有的APP但是它的布局不是全屏的,怎么改啊?

android 7.0点击中间的哪个按钮后显示所有的APP但是它的布局不是全屏的,无论横屏
竖屏都会有空出来的,我现在想直接变成全屏,哪位大佬知道改哪里 啊

3个回答

你把截图发出来,你这语言描述有点不懂啊

xiaxiao_new
xiaxiao_new 但是我发现点击了那个按键之后显示的所有APP的的背景不是全屏的,也就是只有中间的一块区域有APP显示,用上下滑动来显示的,我现在想让整个屏幕来显示,也就是说让这个显示所有APP的区域跟整个屏幕一样的,我试着去改launcher3但是没有效果
大约 2 年之前 回复
xiaxiao_new
xiaxiao_new 是这样,平板电脑开机在下方左边有两个按钮,有右边有两个按钮,中间那个按键点击会显示所有的APP。
大约 2 年之前 回复

你手机是不是全面屏,全面屏可以进行系统设置,设置了非充满屏幕。

xiaxiao_new
xiaxiao_new 我是平板电脑,显示就是显示所有APP的那个界面无法全屏显示,我想让他全屏显示,
大约 2 年之前 回复

那有可能是平板ROM的问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
App自动化报错:Proxy error: Could not proxy command to remote server. Original error: 404 - undefined
    App启动参数如下(存放在Yaml文件中): ``` automationName: UiAutomator2 platformName: Android platformVersion: 7 deviceName: Android Emulator appPackage: com.ellabook appActivity: com.ellabook.startup.StartActivity noReset: False unicodeKeyboard: True # 将键盘给隐藏起来 resetKeyboard: True ```      其他信息:       Appium 1.15       模拟器: 雷电模拟器4.0.7       测试框架: pytest conftest.py内容如下: ``` def basedriver(port=4723, **kwargs): """ 根据设置的参数,启动会话,并返回会话对象 :param port: 会话启动端口号---int :param kwargs: 启动参数 :return: 会话对象 """ yamls = YAML(typ='safe') yaml_path = os.path.join(CAPS_PATH, "desire_caps.yaml") fs = open(yaml_path, encoding='UTF-8') desire_caps = yamls.load(fs) if kwargs: for key, value in kwargs.items(): desire_caps[key] = value driver = webdriver.Remote("http://localhost:{}/wd/hub".format(port), desire_caps) return driver @pytest.fixture(scope="class") def initdriver_first_start(): """App首次启动""" driver = basedriver(noReset=False) yield driver driver.close() ```     测试用例py文件内容: ``` @pytest.mark.usefixtures("initdriver_first_start") class TestAPPStart: """APP启动页测试: 是否进入启动页 、banner图正常滑动、点击"开始看书吧"进入登录界面 """ def test_0_into_start(self, initdriver_first_start): """APP首次启动,启动页是否展示“开始阅读吧”按钮 """ driver = initdriver_first_start AppStartPage(driver).check_read_book_is_exist() def test_banner_left_slip(self, initdriver_first_start): """APP首次启动,启动页广告图能够向左滑""" driver = initdriver_first_start AppStartPage(driver).slide_start_banner("left") # App首次启动,banner广告图正常切换 def test_banner_right_slip(self, initdriver_first_start): """APP首次启动,启动页广告图能够能够向右滑""" driver = initdriver_first_start AppStartPage(driver).slide_start_banner("right") # App首次启动,banner广告图正常切换 def test_click_button(self, initdriver_first_start): """APP首次启动,点击开始按钮,查看是否进入登录界面""" driver = initdriver_first_start AppStartPage(driver).click_start_read() # 点击“开始阅读” 按钮 LoginPage(driver).check_into_login_idle() # 查看是否进入登录界面 ```     APP启动页测试 测试类(pytest/py.test方式)运行,此时用例执行完成后,在进行测试类的teardown时,却报错: selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: 404 - undefined ![图片说明](https://img-ask.csdn.net/upload/201912/26/1577335992_418416.png)  网上百度了一堆资料,但依旧没有相关: 404 - undefined 的报错类型的解决方法(忧伤)
int com_fd = newPort.openPort(uart, 0, (char) longUart);这段代码错在哪里?
package com.example.newland.serialport; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.newland.jni.Convert; import com.newland.jni.SerialPort;//串口类 import com.newland.jni.OnDataReceivedListener;//数据接收监听口 import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.Spinner; import android.widget.ArrayAdapter; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private String strReceiveData="";//串口接收的数据 private Spinner spBaudRate,spUart; private EditText etAck,etSend; private TextView tvUartStatus; private CheckBox chkSendHex,chkAckHex; SerialPort newPort=new SerialPort();//定义一个串口 private int[] sectCom={0,1,2,3}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initComponent();//初始化控件 initSpinnerBaudRate();//初始化下拉框的值 //PC机发送数据是不定时的,故采用响应模式来接收数据 newPort.setCommReceivedMode(true);//设置串口通讯为响应模式 //设置数据接收的监听器 newPort.setOnDataReceivedListener(new OnDataReceivedListener() { public void onDataReceived(String data) { handleReceivedData(data);//处理接受的数据 } }); } /**************************************** * 函数名称:initComponent * 功能描述:初始化界面 * 参数及返回值说明: * ****************************************/ private void initComponent(){ //初始化控件 tvUartStatus=(TextView)findViewById(R.id.tvUartStatus); etAck=(EditText) findViewById(R.id.etAck); etSend=(EditText)findViewById(R.id.etSend); spBaudRate=(Spinner)findViewById(R.id.spBaudRate); spUart=(Spinner)findViewById(R.id.spUart); chkSendHex=(CheckBox)findViewById(R.id.chkSendHex); chkAckHex=(CheckBox)findViewById(R.id.chkAckHex); chkSendHex.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String str=etSend.getText().toString(); try { if (isChecked) { etSend.setText(Convert.stringToHexString(str)); } else { etSend.setText(Convert.hexStringToString(str)); } }catch (Exception e){ } } }); //增加事件监听,实现字符串与十六进制互转 chkAckHex.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String str=etAck.getText().toString(); try { if (isChecked) { etAck.setText(Convert.stringToHexString(str)); } else { etAck.setText(Convert.hexStringToString(str)); } }catch (Exception e){ //TODO:handle exception } } }); } /******* * 函数名称:initSpinnerBaudRate * 功能描述:初始化波特率的值 * 参数及返回值说明:* *******/ private void initSpinnerBaudRate(){ //下拉波特率的值 String[] items={"1200","B2400","B4800","9600","19200","38400","57600","115200","230400","921600"}; //第一步:为下拉列表定义一个适配器,这里就用到里前面定义的items。 final ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items); //第二步:为适配器配置下拉列表下拉时的菜单样式。 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //第三步:将适配器添加到下拉列表上 spBaudRate.setAdapter(adapter); //默认选择第6项--57600 spBaudRate.setSelection(6); //下拉串口的值 String[] uarts={"COM0","COM1","COM2","COM3"}; final ArrayAdapter<String>adapterUart=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,uarts); adapterUart.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spUart.setAdapter(adapterUart); spUart.setSelection(2);//默认选择第二项--COM2 } /******* * 函数名称:myClick * 功能描述:按钮监听 * 参数及返回值说明 *******/ public void myClick(View v) { switch(v.getId()) { //打开串口 case R.id.btnOpenUart: long longUart = spUart.getSelectedItemId(); int uart = sectCom[(int) longUart]; longUart = spBaudRate.getSelectedItemId(); int com_fd = newPort.openPort(uart, 0, (char) longUart); if (com_fd > 0) { tvUartStatus.setText("打开成功!..."); } else { tvUartStatus.setText("打开失败!...");} break; //关闭串口 case R.id.btnCloseUart: newPort.closePort(); tvUartStatus.setText("已关闭!..."); break; //发送 case R.id.btnSend: String msg = etSend.getText().toString(); if (chkSendHex.isChecked()) {//以十六进制数发送 newPort.sendCommand(Convert.hexStringToCharArray(msg)); } else {//以字符串发送 newPort.sendCommand(Convert.stringToCharArray(msg)); } break; //清除按钮 case R.id.btnClear: etAck.setText(""); strReceiveData = ""; break; //退出 case R.id.btnQuit: System.exit(0); default: break; } } /************ * 函数名称:handleReceiveData * 功能描述:处理数据 * 参数说明:data,从串口中接收到的数据 ************/ protected void handleReceivedData(final String data){ runOnUiThread(new Runnable() {//通过runOnUiThread在线程中执行UI更新操作 public void run() { strReceiveData = strReceiveData + data; if (chkAckHex.isChecked()) {//十六进制显示 etAck.setText(Convert.dataToHexString(strReceiveData)); }else { etAck.setText(Convert.dataToHexString(strReceiveData));} } }); } @Override protected void onDestroy(){ super.onDestroy(); newPort.onDestroy(); } } E/JIN: WARNING:could not load libuart.so E/zygote: No implementation found for int com.newland.jni.Linuxc.openUart(int, int) (tried Java_com_newland_jni_Linuxc_openUart and Java_com_newland_jni_Linuxc_openUart__II) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.newland.serialport, PID: 25212 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) at android.view.View.performClick(View.java:6256)  at android.view.View$PerformClick.run(View.java:24701)  at android.os.Handler.handleCallback(Handler.java:789)  at android.os.Handler.dispatchMessage(Handler.java:98)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  Caused by: java.lang.UnsatisfiedLinkError: No implementation found for int com.newland.jni.Linuxc.openUart(int, int) (tried Java_com_newland_jni_Linuxc_openUart and Java_com_newland_jni_Linuxc_openUart__II) at com.newland.jni.Linuxc.openUart(Native Method) at com.newland.jni.SerialPort.openPort(SerialPort.java:87) at com.example.newland.serialport.MainActivity.myClick(MainActivity.java:132) at java.lang.reflect.Method.invoke(Native Method)  at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)  at android.view.View.performClick(View.java:6256)  at android.view.View$PerformClick.run(View.java:24701)  at android.os.Handler.handleCallback(Handler.java:789)  at android.os.Handler.dispatchMessage(Handler.java:98)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  Application terminated.
用荣耀9调试显示[ThreadDexHotfixMonitor]Bind hotfix monitor service fail!
有没有大佬看看这是什么问题啊,用荣耀9调试的时候日志显示[ThreadDexHotfixMonitor]Bind hotfix monitor service fail! 手机上打开了开发者模式,android studio也能连上,就想发条通知,但怎么点击按钮都没用。下面是debug日志 10-02 17:16:04.256 16362-16362/? I/otificationtes: Late-enabling -Xcheck:jni 10-02 17:16:04.330 16362-16362/? I/otificationtes: Reinit property: dalvik.vm.checkjni= false 10-02 17:16:04.346 16362-16362/? D/ZrHung.AppEyeUiProbe: AppEyeUIP created. 10-02 17:16:04.349 16362-16362/? D/ActivityThread: Attach thread to application 10-02 17:16:04.432 16362-16393/com.example.notificationtest I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.notificationtest#10223#256 10-02 17:16:04.434 16362-16393/com.example.notificationtest I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.notificationtest#10223#0 10-02 17:16:04.457 16362-16362/com.example.notificationtest I/InstantRun: Instant Run Runtime started. Android package is com.example.notificationtest, real application class is null. 10-02 17:16:04.642 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden method Ldalvik/system/BaseDexClassLoader;->getLdLibraryPath()Ljava/lang/String; (light greylist, reflection) 10-02 17:16:04.644 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:04.770 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:04.770 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:04.842 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:04.843 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:04.933 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:04.933 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.006 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.007 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.092 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.093 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.163 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.164 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.243 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.244 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.342 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.343 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.442 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.442 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.526 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.527 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.659 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.660 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.746 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.746 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.817 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.818 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:05.946 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:05.947 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.055 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.056 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.182 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.183 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.305 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.306 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.493 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.494 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.710 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.711 16362-16362/com.example.notificationtest W/otificationtes: Unsupported class loader 10-02 17:16:06.785 16362-16362/com.example.notificationtest W/otificationtes: Skipping duplicate class check due to unsupported classloader 10-02 17:16:06.787 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Ljava/lang/ClassLoader;->parent:Ljava/lang/ClassLoader; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden method Landroid/app/ActivityThread;->currentActivityThread()Landroid/app/ActivityThread; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/ActivityThread;->mInitialApplication:Landroid/app/Application; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/ActivityThread;->mAllApplications:Ljava/util/ArrayList; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/LoadedApk;->mApplication:Landroid/app/Application; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/LoadedApk;->mResDir:Ljava/lang/String; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/Application;->mLoadedApk:Landroid/app/LoadedApk; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/ActivityThread;->mPackages:Landroid/util/ArrayMap; (light greylist, reflection) 10-02 17:16:06.790 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden field Landroid/app/ActivityThread;->mResourcePackages:Landroid/util/ArrayMap; (light greylist, reflection) 10-02 17:16:06.795 16362-16393/com.example.notificationtest I/AwareBitmapCacher: init processName:com.example.notificationtest pid=16362 uid=10223 10-02 17:16:06.798 16362-16791/com.example.notificationtest E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@28ac4fd 10-02 17:16:06.798 16362-16791/com.example.notificationtest E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@d43b3f9 10-02 17:16:06.800 16362-16362/com.example.notificationtest D/ZrHung.AppEyeUiProbe: notify runnable to start. 10-02 17:16:06.802 16362-16793/com.example.notificationtest D/ZrHung.AppEyeUiProbe: Runnable thread started. 10-02 17:16:06.802 16362-16393/com.example.notificationtest E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist! 10-02 17:16:06.802 16362-16793/com.example.notificationtest D/IMonitor: Load library imonitor_jni 10-02 17:16:06.904 16362-16362/com.example.notificationtest I/HwApsImpl: APS: new HwApsImpl created 10-02 17:16:06.911 16362-16362/com.example.notificationtest I/HwPhoneWindow: updateLayoutParamsColor false mSpecialSet=false, mForcedNavigationBarColor=false, navigationBarColor=0, mNavBarShow=false, mIsFloating=false 10-02 17:16:06.911 16362-16362/com.example.notificationtest I/HwPhoneWindow: updateLayoutParamsColor true mSpecialSet=true, mForcedNavigationBarColor=false, navigationBarColor=fffcfcfc, mNavBarShow=false, mIsFloating=false 10-02 17:16:06.934 16362-16362/com.example.notificationtest I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config 10-02 17:16:06.934 16362-16362/com.example.notificationtest I/OverScrollerOptimization: get the overscroller config 10-02 17:16:06.938 16362-16362/com.example.notificationtest I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.938 16362-16362/com.example.notificationtest I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.938 16362-16362/com.example.notificationtest D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.938 16362-16362/com.example.notificationtest D/FeatureFactory: loadFeature() new IHwSplineOverScrollerEx() 10-02 17:16:06.939 16362-16362/com.example.notificationtest D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@5f9433,android.support.v7.view.ContextThemeWrapper@a4bd3f0 10-02 17:16:06.940 16362-16362/com.example.notificationtest D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0 10-02 17:16:06.941 16362-16362/com.example.notificationtest I/FLTAG_FM: loadFeature class:com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.941 16362-16362/com.example.notificationtest I/FLTAG_SFM: getRequireClassLoader() succ ! className: com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.941 16362-16362/com.example.notificationtest D/FeatureFactory: loadFeature() : com.huawei.featurelayer.systemfeature.HwWidget.IHwSplineOverScrollerEx 10-02 17:16:06.941 16362-16362/com.example.notificationtest D/FeatureFactory: loadFeature() new IHwSplineOverScrollerEx() 10-02 17:16:06.941 16362-16362/com.example.notificationtest D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl paras: android.widget.OverScroller$SplineOverScroller@b323f1c,android.support.v7.view.ContextThemeWrapper@a4bd3f0 10-02 17:16:06.941 16362-16362/com.example.notificationtest D/HwSplineOverScrollerExImpl: initSplineOverScrollerImpl: mScrollerVelocity is 0, value is 0 10-02 17:16:06.979 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) 10-02 17:16:06.980 16362-16362/com.example.notificationtest W/otificationtes: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection) 10-02 17:16:06.990 16362-16362/com.example.notificationtest D/TextView: get Display Panel Type is : 0 10-02 17:16:07.005 16362-16362/com.example.notificationtest D/ActivityThread: add activity client record, r= ActivityRecord{29dbe14 token=android.os.BinderProxy@b543ac0 {com.example.notificationtest/com.example.notificationtest.MainActivity}} token= android.os.BinderProxy@b543ac0 10-02 17:16:07.010 16362-16362/com.example.notificationtest D/ZrHung.AppEyeUiProbe: notify runnable to start. 10-02 17:16:07.021 16362-16362/com.example.notificationtest D/OpenGLRenderer: Skia GL Pipeline 10-02 17:16:07.027 16362-16362/com.example.notificationtest D/HwAppInnerBoostImpl: set config for com.example.notificationtest BOOST_FLAG=false REPORT_DURATION_CLICK=1000 REPORT_TIMES_CLICK=3 REPORT_DURATION_SLIDE=5000 REPORT_TIMES_SLIDE=16 10-02 17:16:07.028 16362-16362/com.example.notificationtest D/OpenGLRenderer: HWUI Binary is enabled 10-02 17:16:07.028 16362-16362/com.example.notificationtest D/OpenGLRenderer: disableOutlineDraw is true 10-02 17:16:07.053 16362-16799/com.example.notificationtest I/HiTouch_HiTouchSensor: enabledInPad = false,isPcCastMode = false 10-02 17:16:07.055 16362-16799/com.example.notificationtest D/HiTouch_PressGestureDetector: onAttached, package=com.example.notificationtest, windowType=1, mHiTouchRestricted=false 10-02 17:16:07.099 16362-16797/com.example.notificationtest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 10-02 17:16:07.099 16362-16797/com.example.notificationtest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 10-02 17:16:07.101 16362-16797/com.example.notificationtest I/iGraphics: [0020080c] pn: com.example.notificationtest, p: 16362 10-02 17:16:07.101 16362-16797/com.example.notificationtest I/iGraphics: [0030080c] no spt app: com.example.notificationtest 10-02 17:16:07.101 16362-16797/com.example.notificationtest I/OpenGLRenderer: Initialized EGL, version 1.4, mEglDisplay 0x1 10-02 17:16:07.101 16362-16797/com.example.notificationtest D/OpenGLRenderer: Swap behavior 2 10-02 17:16:07.114 16362-16797/com.example.notificationtest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 10-02 17:16:07.374 16362-16362/com.example.notificationtest W/InputMethodManager: startInputReason = 1 10-02 17:16:07.389 16362-16362/com.example.notificationtest W/InputMethodManager: startInputReason = 5 10-02 17:16:09.655 16362-16418/com.example.notificationtest W/ServiceManager: Service huawei.android.security.IAppBehaviorDataAnalyzer didn't start. Returning NULL 10-02 17:16:09.655 16362-16418/com.example.notificationtest E/[HOTFIX]: [ThreadDexHotfixMonitor]Bind hotfix monitor service fail! 10-02 17:16:11.803 16362-16362/com.example.notificationtest D/AwareBitmapCacher: handleInit switch not opened pid=16362 10-02 17:16:13.556 16362-16362/com.example.notificationtest W/Settings: Setting device_provisioned has moved from android.provider.Settings.Secure to android.provider.Settings.Global. 10-02 17:16:13.614 16362-16362/com.example.notificationtest I/ViewRootImpl: jank_removeInvalidNode jank list is null 10-02 17:16:13.744 16362-16362/com.example.notificationtest D/HwGalleryCacheManagerImpl: mIsEffect:false 10-02 17:16:20.627 16362-16362/com.example.notificationtest I/ViewRootImpl: jank_removeInvalidNode all the node in jank list is out of time
自学Android开发 在模拟器运行闪退
初学者自写的程序 ,但是在模拟器下运行闪退!!该怎么改呀?? package com.example.work3; import java.util.ArrayList; import java.util.List; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.TabActivity; import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.StrictMode; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Spinner; import android.widget.TabHost; import android.widget.TextView; import android.os.Build; public class MainActivity extends TabActivity { private TabHost tabhost; private ListView listview; private ArrayAdapter<String> arr_adapter; private Spinner spinner; private List<String>list; private ArrayAdapter<String> adapter; private EditText et1,et2; private Button bt; String name; String value; String style; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); et1=(EditText) findViewById(R.id.editText1); et2=(EditText) findViewById(R.id.editText2); bt=(Button) findViewById(R.id.button1); setContentView(R.layout.activity_main); tabhost=getTabHost(); tabhost.addTab(tabhost.newTabSpec("菜单一").setIndicator("首页").setContent(R.id.tab1)); tabhost.addTab(tabhost.newTabSpec("菜单二").setIndicator("新增").setContent(R.id.tab2)); tabhost.addTab(tabhost.newTabSpec("菜单三").setIndicator("账单").setContent(R.id.tab3)); //按钮监听 提取信息 bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub name = et1.getText().toString(); value = et2.getText().toString(); style = spinner.getSelectedItem().toString(); } }); listview = (ListView) findViewById(R.id.listview); //新建适配器 String[]arr_data={"数据1","数据2","数据3","数据4","数据5"}; //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) arr_adapter =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arr_data); listview.setAdapter(arr_adapter); spinner=(Spinner) findViewById(R.id.spinner); //数据源 String[]list = {"1.日常食品支出","2.人情世故支出","3.出差旅游支出","4.服饰鞋帽支出","5.生活用品支出","6.其他支出"}; //新建适配器 adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); //设置下拉样式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //加载适配器 spinner.setAdapter(adapter); } //退出对话框 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK ) { // 创建退出对话框 AlertDialog isExit = new AlertDialog.Builder(this).create(); // 设置对话框标题 isExit.setTitle("系统提示"); // 设置对话框消息 isExit.setMessage("确定要退出吗"); // 添加选择按钮并注册监听 isExit.setButton("确定", listener); isExit.setButton2("取消", listener); // 显示对话框 isExit.show(); } return false; } /**监听对话框里面的button点击事件*/ DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序 finish(); break; case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框 break; default: break; } } }; }
Android Studio自定义布局中的Button不响应点击事件
最近开始跟着郭霖大神的《第一行代码》学习Android开发,遇到一个问题 自定义布局之后,模拟器运行时Button不响应单击事件 代码如下 MainActivity.java package com.example.uilayouttest; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); if (actionBar != null){ actionBar.hide(); } } } activity_main.xml文件 <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!--android:orientation="horizontal"--> <include layout="@layout/title"/> <com.example.uilayouttest.TitleLayout android:layout_width="match_parent" android:layout_height="wrap_content"> </com.example.uilayouttest.TitleLayout> </LinearLayout> title.xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="65dp" android:background="@drawable/back_bg" > <Button android:id="@+id/title_back" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="top" android:layout_margin="5dp" android:text="Back" android:textColor="#fff"/> <TextView android:id="@+id/title_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_weight="1" android:gravity="center" android:text="Title Text" android:textColor="#fff" android:textSize="28sp"/> <Button android:id="@+id/title_edit" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="top" android:layout_margin="5dp" android:background="@drawable/edit" android:text="" /> </LinearLayout> TitleLayout.java类 package com.example.uilayouttest; import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; public class TitleLayout extends LinearLayout { public TitleLayout(Context context, AttributeSet attrs){ super(context,attrs); LayoutInflater.from(context).inflate(R.layout.title, this); Button titleBack = (Button) findViewById(R.id.title_back); Button titleEdit = (Button) findViewById(R.id.title_edit); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity) getContext()).finish(); Log.d("data", "onClick:到底有没有点击我 "); Toast.makeText(getContext(), "你点击了Back按钮", Toast.LENGTH_SHORT).show(); } }); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "你点击了Edit按钮", Toast.LENGTH_SHORT).show(); } }); } } ``` ```
android studio连接web报错?
1.问题描述 可以通过浏览器连接web应用,但用android studio连接报错 2.代码如下 Android端 **activity_main.xml:** <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 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" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名 " /> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" /> <Button android:onClick="click1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="get"/> <Button android:onClick="click2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="post"/> </LinearLayout> </android.support.constraint.ConstraintLayout> ``` ``` MainActivity private EditText username; private EditText password; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); username = (EditText) findViewById(R.id.et_username); password = (EditText) findViewById(R.id.et_password); } public void click1(View v) { new Thread() { @Override public void run() { super.run(); } }.start(); try { String name = username.getText().toString().trim(); String pwd = password.getText().toString().trim(); String path = "http://10.0.2.2:8080/login/loginServlet?username=" + name + "&password=" + pwd + ""; URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); int code = conn.getResponseCode(); if (code == 200) { showToast("连接成功"); } } catch (Exception e) { e.printStackTrace(); } } public void click2(View v) { } public void showToast(final String content) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show(); } }); } } ``` ``` AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.administrator.myapplication1"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ``` ``` 点击按钮后的日志 05-01 04:50:39.613 9826-9826/? I/art: Not late-enabling -Xcheck:jni (already on) 05-01 04:50:39.613 9826-9826/? W/art: Unexpected CPU variant for X86 using defaults: x86 05-01 04:50:39.911 9826-9826/com.example.administrator.myapplication1 W/System: ClassLoader referenced unknown path: /data/app/com.example.administrator.myapplication1-2/lib/x86 05-01 04:50:39.933 9826-9826/com.example.administrator.myapplication1 I/InstantRun: starting instant run server: is main process 05-01 04:50:40.140 9826-9826/com.example.administrator.myapplication1 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 I/OpenGLRenderer: Initialized EGL, version 1.4 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 D/OpenGLRenderer: Swap behavior 1 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 05-01 04:50:40.727 9826-9852/com.example.administrator.myapplication1 D/OpenGLRenderer: Swap behavior 0 05-01 04:50:40.896 9826-9826/com.example.administrator.myapplication1 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView 05-01 04:51:59.575 9826-9826/com.example.administrator.myapplication1 W/IInputConnectionWrapper: finishComposingText on inactive InputConnection 05-01 04:52:02.649 9826-9826/com.example.administrator.myapplication1 D/NetworkSecurityConfig: No Network Security Config specified, using platform default 05-01 04:52:02.651 9826-9826/com.example.administrator.myapplication1 W/System.err: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:333) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356) 05-01 04:52:02.652 9826-9826/com.example.administrator.myapplication1 W/System.err: at java.net.Socket.connect(Socket.java:605) at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113) at com.android.okhttp.Connection.connectSocket(Connection.java:196) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521) at com.example.administrator.myapplication1.MainActivity.click1(MainActivity.java:44) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22429) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) 05-01 04:52:02.655 9826-9826/com.example.administrator.myapplication1 W/System.err: at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
各位大神,求助!关于安卓的线程.发送数据的按钮每次只能按一次,按第二次程序就崩溃,求解!
代码如下,中间有一段GPS取位置的可以不用在意,注意问题就是我按发送按钮就会发送信息,但是再按一次程序就会崩溃,求帮忙!谢谢! package com.example.zhb.wifi3; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.Socket; import java.io.OutputStream; import android.os.Bundle; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.view.View.OnClickListener; public class MainActivity extends AppCompatActivity { private Button sbutton = null; private Button getlocation = null; private TextView locations = null; private double latitude; private double longitude; public Thread t=new Thread(new MyThread()); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //setSupportActionBar(toolbar); sbutton = (Button)findViewById(R.id.Button01); getlocation = (Button)findViewById(R.id.Button02); locations = (TextView)findViewById(R.id.textView); getlocation.setOnClickListener(new OnClickListener() { public void onClick(View v) { getLocation(); } }); sbutton.setOnClickListener(new OnClickListener() { public void onClick(View v) { t.start(); } }); } public void getLocation(){ LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ try{Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location != null){ latitude = location.getLatitude(); longitude = location.getLongitude(); } } catch(SecurityException e){} }else{ LocationListener locationListener = new LocationListener() { // Provider的状态在可用、暂时不可用和无服务三个状态直接切换时触发此函数 @Override public void onStatusChanged(String provider, int status, Bundle extras) { } // Provider被enable时触发此函数,比如GPS被打开 @Override public void onProviderEnabled(String provider) { } // Provider被disable时触发此函数,比如GPS被关闭 @Override public void onProviderDisabled(String provider) { } //当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发 @Override public void onLocationChanged(Location location) { if (location != null) { Log.e("Map", "Location changed : Lat: " + location.getLatitude() + " Lng: " + location.getLongitude()); } } }; try{Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000, 0,locationListener); if(location != null){ latitude = location.getLatitude(); //经度 longitude = location.getLongitude(); //纬度 } } catch(SecurityException e){} } locations.setText("当前经纬度:"+latitude+";"+longitude); } public class MyThread implements Runnable { @Override public void run() { // TODO Auto-generated method stub try{ //建立连接到远程服务器的Socket Socket socket=new Socket("192.168.1.218",8080); //OutputStream os = socket.getOutputStream(); String a=String.valueOf(latitude); String b=String.valueOf(longitude); Writer writer=new OutputStreamWriter(socket.getOutputStream()); writer.write("latitude:"+a+" longitude:"+b+"\n"); writer.flush(); writer.close(); socket.close(); }catch(IOException e){ System.out.println("出错了"); } } } } ``` ```
android Adapter空指针问题 求大神看看 解决不了
是这样的。我是在做一个相当于一个手机卫士,里面有通讯录和黑名单两个功能。这个代码是我做的黑名单里的。![图片说明](https://img-ask.csdn.net/upload/201706/17/1497695379_112155.png) 想实现的功能是点黑名单按钮,可以出现这个黑名单的Activity。通讯录做了一个Listview,点通讯录按钮,可以导入系统通讯录,然后设置点击监听,长按item可以发短信,点击可以打电话。 现在的问题是,无论是通讯录还是黑名单,一点按钮就报错,报错的内容就是空指针。不知道怎么觉得。哭唧唧。 这个是代码。无论尝试什么方法,都报错空指针。 package com.jinwen.pengu.communication; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class Stop extends Activity { private ListView iv_main; private BlackNumberAdapter adapter; private BlackNumberDao dao; private List<BlackNumber> data; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_main = (ListView) findViewById(R.id.iv_main); adapter = new BlackNumberAdapter(); dao = new BlackNumberDao(this); data = dao.getAll(); iv_main.setAdapter(adapter); } public void add(View v){ } class BlackNumberAdapter extends BaseAdapter{ @Override public int getCount() { return data.size(); } @Override public Object getItem(int position) { return data.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView ==null){ convertView = View.inflate(Stop.this,android.R.layout.simple_list_item_1,null); } BlackNumber blackNumber = data.get(position); TextView textView = (TextView) convertView.findViewById(android.R.id.text1); textView.setText(blackNumber.getNumber()); return convertView; } } } 错误: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference at com.jinwen.pengu.communication.Stop.onCreate(Stop.java:31)
Android app开发:按钮拖动后单点按钮 所有按钮回到原来位置
拖动按钮后 ![图片说明](https://img-ask.csdn.net/upload/201807/13/1531471810_88626.png) 然后摁了按钮数字7 ![图片说明](https://img-ask.csdn.net/upload/201807/13/1531471833_980413.png) 所有按钮回到原位 这是关于按钮7的代码 number[7].setOnTouchListener(new OnTouchListener() {//设置按钮被触摸的时间 int lastX, lastY; // 记录移动的最后的位置 @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub int ea = event.getAction();//获取事件类型 switch (ea) { case MotionEvent.ACTION_DOWN: // 按下事件 lastX = (int) event.getRawX(); lastY = (int) event.getRawY(); downX = lastX; downY = lastY; break; case MotionEvent.ACTION_MOVE: // 拖动事件 // 移动中动态设置位置 int dx = (int) event.getRawX() - lastX;//位移量X int dy = (int) event.getRawY() - lastY;//位移量Y int left = v.getLeft() + dx; int top = v.getTop() + dy; int right = v.getRight() + dx; int bottom = v.getBottom() + dy; //++限定按钮被拖动的范围 if (left < 0) { left = 0; right = left + v.getWidth(); } if (right > screenWidth) { right = screenWidth; left = right - v.getWidth(); } if (top < 0) { top = 0; bottom = top + v.getHeight(); } if (bottom > v.getHeight()) { bottom = v.getHeight(); top = bottom - v.getHeight(); } //--限定按钮被拖动的范围 v.layout(left, top, right, bottom);//按钮重画 // 记录当前的位置 lastX = (int) event.getRawX(); lastY = (int) event.getRawY(); break; case MotionEvent.ACTION_UP: // 弹起事件 //判断是单击事件或是拖动事件,位移量大于5则断定为拖动事件 if (Math.abs((int) (event.getRawX() - downX)) > 5 || Math.abs((int) (event.getRawY() - downY)) > 5) clickormove = false; else clickormove = true; break; } return false; } }); number[7].setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(clickormove) { utils.soundPlay(7); // TODO Auto-generated method stub if(flag==1){ str=""; str+=7; et.setText(str); flag=0; } else{ str+=7; et.setText(str); } vi=v; }} }); ``` ```
PagerView的一个子页面里的ListView显示不出来
Android初学者,最近的一个仿QQ的作业,看了网上的做法用PagerView做了个类似QQ那种底部标签栏可以切换页面的样式,然后我在其中一个页面里加了个ListView,在ListView里面放了几项数据,但是显示不出来,困扰了我好久,网上找了好久,就是解决不了,求大神帮忙看看,谢谢谢谢!!! 把listview单独出来运行可以显示,或者在listview所在的布局里添加其他类型的组件也可以显示,维度listview不显示 这是实现三个Tab切换页面的Java代码 ``` import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class Top_bottom extends Activity implements android.view.View.OnClickListener { private ViewPager mViewPager;// 用来放置界面切换 private PagerAdapter mPagerAdapter;// 初始化View适配器 private List<View> mViews = new ArrayList<View>();// 用来存放Tab01-03 // 三个Tab,每个Tab包含一个按钮 private LinearLayout mTabMessage; private LinearLayout mTabContacts; private LinearLayout mTabDynamic; // 三个按钮 private ImageButton mMessageImg; private ImageButton mContactsImg; private ImageButton mDynamicImg; //顶部标题 private TextView textView; //底部标签 private TextView textView_message; private TextView textView_contacts; private TextView textView_dynamic; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.top_bottom); textView=(TextView)findViewById(R.id.top_textview); textView_message=(TextView)findViewById(R.id.textView_message); textView_contacts=(TextView)findViewById(R.id.textView_contacts); textView_dynamic=(TextView)findViewById(R.id.textView_dynamic); initView(); initViewPage(); initEvent(); } private void initEvent() { mTabMessage.setOnClickListener(this); mTabContacts.setOnClickListener(this); mTabDynamic.setOnClickListener(this); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { /** *ViewPage左右滑动时 */ @Override public void onPageSelected(int arg0) { int currentItem = mViewPager.getCurrentItem(); switch (currentItem) { case 0: textView.setText("消息"); resetImg(); mMessageImg.setBackground(getResources().getDrawable(R.drawable.messages,null)); textView_message.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; case 1: textView.setText("联系人"); resetImg(); mContactsImg.setBackground(getResources().getDrawable(R.drawable.contactss,null)); textView_contacts.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; case 2: textView.setText("动态"); resetImg(); mDynamicImg.setBackground(getResources().getDrawable(R.drawable.qzones,null)); textView_dynamic.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; default: break; } } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } /** * 初始化设置 */ private void initView() { mViewPager = (ViewPager) findViewById(R.id.viewpager); // 初始化三个LinearLayout mTabMessage = (LinearLayout) findViewById(R.id.tab_message); mTabContacts = (LinearLayout) findViewById(R.id.tab_contacts); mTabDynamic = (LinearLayout) findViewById(R.id.tab_dynamic); // 初始化三个按钮 mMessageImg = (ImageButton) findViewById(R.id.tab_message_img); mContactsImg = (ImageButton) findViewById(R.id.tab_contacts_img); mDynamicImg = (ImageButton) findViewById(R.id.tab_dynamic_img); } /** * 初始化ViewPage */ private void initViewPage() { // 初始化三个布局 LayoutInflater mLayoutInflater = LayoutInflater.from(this); View message = mLayoutInflater.inflate(R.layout.message, null); View contacts = mLayoutInflater.inflate(R.layout.contacts, null); View dynamic = mLayoutInflater.inflate(R.layout.dynamic,null); mViews.add(message); mViews.add(contacts); mViews.add(dynamic); // 适配器初始化并设置 mPagerAdapter = new PagerAdapter() { @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(mViews.get(position)); } @Override public Object instantiateItem(ViewGroup container, int position) { View view = mViews.get(position); container.addView(view); return view; } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public int getCount() { return mViews.size(); } }; mViewPager.setAdapter(mPagerAdapter); } /** * 判断哪个要显示,及设置按钮图片 */ @Override public void onClick(View arg0) { switch (arg0.getId()) { case R.id.tab_message: textView.setText("消息"); mViewPager.setCurrentItem(0); resetImg(); mMessageImg.setBackground(getResources().getDrawable(R.drawable.messages,null)); textView_message.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; case R.id.tab_contacts: textView.setText("联系人"); mViewPager.setCurrentItem(1); resetImg(); mContactsImg.setBackground(getResources().getDrawable(R.drawable.contactss,null)); textView_contacts.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; case R.id.tab_dynamic: textView.setText("动态"); mViewPager.setCurrentItem(2); resetImg(); mDynamicImg.setBackground(getResources().getDrawable(R.drawable.qzones,null)); textView_dynamic.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); break; default: break; } } /** * 把所有图片变暗 */ private void resetImg() { mMessageImg.setBackground(getResources().getDrawable(R.drawable.message,null)); mContactsImg.setBackground(getResources().getDrawable(R.drawable.contacts,null)); mDynamicImg.setBackground(getResources().getDrawable(R.drawable.qzone,null)); textView_message.setTextColor(getResources().getColor(R.color.colorfont)); textView_contacts.setTextColor(getResources().getColor(R.color.colorfont)); textView_dynamic.setTextColor(getResources().getColor(R.color.colorfont)); } public void onBackPressed() { Intent intent = new Intent(); intent.setAction("android.intent.action.MAIN"); intent.addCategory("android.intent.category.HOME"); startActivity(intent); } } ``` ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/activity_top"></include> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> <include layout="@layout/activity_bottom"></include> </LinearLayout> ``` 这是实现ListView的Java代码 ``` import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ListView; import android.widget.SimpleAdapter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Dynamic extends AppCompatActivity { private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dynamic); listView=(ListView)findViewById(R.id.listview_dynamic); String title[]={"好友动态","退出QQ"}; int img[]={R.drawable.qqzone,R.drawable.exit}; List<Map<String,Object>> list=new ArrayList<Map<String, Object>>(); //List集合用来封装数据 for (int x=0;x<title.length;x++){ Map<String,Object> map=new HashMap<String,Object>(); map.put("title",getResources().getStringArray(R.array.title)[x]); map.put("img",img[x]); list.add(map); //将封装后的每个Item的数据添加到List集合中 } SimpleAdapter simpleAdapter=new SimpleAdapter(Dynamic.this,list,R.layout.dynamic_style, new String[]{"title","img"},new int[]{R.id.textView21,R.id.imageView2}); listView.setAdapter(simpleAdapter); } } ```
Android项目一点录音按钮就停止运行
package com.example.task314; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.os.SystemClock; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.Window; import android.widget.Button; import android.widget.Chronometer; import android.widget.Toast; /** * 在Android上编写一个程序,能够启动本机的录音功能、拍照功能、摄像功能。不考虑权限问题 * @author Administrator * */ public class Sound extends Activity { private Button bt1 = null; private Button bt2 = null; private Chronometer ch1 =null; private MediaRecorder mr = null; private String PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/media"; private int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_sound); bt1 = (Button)this.findViewById(R.id.button1); bt2 = (Button)this.findViewById(R.id.button2); ch1 = (Chronometer)findViewById(R.id.chronometer1); //创建一个临时的音频输出文件 // audioFile = File.createTempFile("record_", ".amr"); //第4步:指定音频输出文件 // mediaRecorder.setOutputFile(audioFile.getAbsolutePath()); File file = new File(PATH); if (!file.exists()) { //按照指定的路径创建文件夹 file.mkdirs(); } bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mr = new MediaRecorder(); // 第1步:设置音频来源(MIC表示麦克风) mr.setAudioSource(MediaRecorder.AudioSource.MIC); //第2步:设置音频输出格式(默认的输出格式) mr.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); //第3步:设置音频编码方式(默认的编码方式) mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss"); String date = sDateFormat.format(new java.util.Date()); System.out.println("time---"+date); String mFileName = PATH + "/"+date+".amr"; mr.setOutputFile(mFileName); // System.out.println(""+audioFile.getAbsolutePath().toString()); //第5步:调用prepare方法 try { mr.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //第6步:调用start方法开始录音 mr.start(); //启动计时器 // ch1.setBase(SystemClock.elapsedRealtime()); ch1.start(); Toast.makeText(getApplicationContext(), "开启", 0).show(); bt1.setEnabled(false); } }); bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub //第7步:停止录音 if(mr != null ) { mr.stop(); ch1.stop(); ch1.setBase(SystemClock.elapsedRealtime()); Toast.makeText(getApplicationContext(), "关闭", 0).show(); bt1.setEnabled(true); } } }); } }
android studio 与后台交互问题 网络访问的问题
url返回了我需要的值 只有我在控制台点击url的时候 服务器端才会有反应 HttpResponse response = httpClient.execute(httpGet);不执行 代码如下: package com.cy.mynj.com.cy.mynj.login; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.cy.mynj.R; import com.cy.mynj.com.cy.mynj.activities.MainActivity; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; public class LoginActivity extends AppCompatActivity implements View.OnClickListener{ private EditText et_phone; private EditText et_password; private Button btn_login; private TextView tv_login_register; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); initViews(); } private void initViews() { et_phone=(EditText)findViewById(R.id.et_phone); et_password=(EditText)findViewById(R.id.et_password); btn_login=(Button)findViewById(R.id.btn_login); btn_login.setOnClickListener(this); tv_login_register=(TextView)findViewById(R.id.tv_login_register); tv_login_register.setOnClickListener(this); tv=(TextView)findViewById(R.id.tv); } @Override public void onClick(View view) { String phone = et_phone.getText().toString(); String password=et_password.getText().toString(); System.out.println(phone + "," + password); System.out.println("按钮点击的线程的名字为:" + Thread.currentThread().getName()); Mythread mythread= new Mythread(phone,password); mythread.start(); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); tv.setText(Thread.currentThread().getName() + msg.obj); // 在把这个字符串变成一个JSONObejct try { JSONObject obj = new JSONObject(msg.obj.toString()); String value = obj.getString("loginstate"); System.out.println("value-->" + value); if (value.equals("success")) { Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); } else { Toast.makeText(LoginActivity.this, "登录失败",Toast.LENGTH_SHORT ).show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; private class Mythread extends Thread { private String phone; private String password; public Mythread(String phone, String password) { this.phone = phone; this.password = password; } @Override public void run () { // 在线程中请求服务器的资源 // Apache HttpClient // 1.创建HttpClient对象 HttpClient httpClient = new DefaultHttpClient(); Log.d("test", "t0"); // 2.构建请求的URL String url = "http://172.20.10.3:8080/appnews/user?phone=" + phone + "&password=" + password + "&operator=login"; // String url = "http://10.0.2.2:8080/appnews/servlet/StudentServlet"; // 3.创建HttpGet请求的对象 HttpGet httpGet = new HttpGet(url); Log.d("test4", "t4"); // 4.使用创建的httpClient执行这个httpGet请求 try { HttpResponse response = httpClient.execute(httpGet); Log.d("test3", "t3"); // 5.判断服务器端请求和应答是否成功 if (response.getStatusLine().getStatusCode() == 200) { System.out.println("请求和应答成功"); // 服务器端传输的数据的一个android封装的对象 HttpEntity entity = response.getEntity(); String msg = EntityUtils.toString(entity, "UTF-8"); System.out.println("server-->" + msg); // 在android中,子线程不能更新界面组件的值, // 因为界面组件是单线程模型,必须回到主线程更新组件的值。 // tv.setText(msg); // 构建消息对象 Message smsg = new Message(); smsg.obj = msg; handler.sendMessage(smsg); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block Log.d("test5", "t5"); e.printStackTrace(); } } } }
关于安卓内存泄露的问题
小弟最近在做一个小项目,基本上功能完成了,但发现在程序运行了几分钟后会自动退出,打印的日志信息如下: ![图片说明](https://img-ask.csdn.net/upload/201907/22/1563795606_231565.png) 然后又通过对程序进行注释后发现在将从服务器获取数据的功能注释掉后这个问题解决了,所以觉得问题应该是出在这一块,在这个功能中循环调用的函数有关于对象以及线程,不知是否是这一块的问题,现将整个程序贴上求大神帮忙看看: MainActivity中: ``` package com.example.gsontest; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.Toast; import com.baidu.location.BDLocation; import com.baidu.location.BDLocationListener; import com.baidu.location.LocationClient; import com.baidu.location.LocationClientOption; import com.baidu.mapapi.SDKInitializer; import com.baidu.mapapi.map.BaiduMap; import com.baidu.mapapi.map.BitmapDescriptor; import com.baidu.mapapi.map.BitmapDescriptorFactory; import com.baidu.mapapi.map.MapStatusUpdate; import com.baidu.mapapi.map.MapStatusUpdateFactory; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.MarkerOptions; import com.baidu.mapapi.map.MyLocationConfiguration; import com.baidu.mapapi.map.MyLocationData; import com.baidu.mapapi.map.OverlayOptions; import com.baidu.mapapi.model.LatLng; import com.baidu.mapapi.utils.CoordinateConverter; import org.json.JSONObject; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class MainActivity extends AppCompatActivity { private MapView mapView; private BaiduMap baiduMap; public LocationClient mLocationClient; public static String responseData; public double dvalueX; public double dvalueY; private boolean isFirstLocate = true; public int mXDirection; //方向类的对象 public MyOrientationListener myOrientationListener; @Override //该函数主要是进行Activity初始化 protected void onCreate(Bundle savedInstanceState) { Log.i("MainActivity","进入到onCreate函数中进行初始化"); super.onCreate(savedInstanceState); //实例化对象 mLocationClient = new LocationClient(getApplicationContext()); //注册监听器 mLocationClient.registerLocationListener(new MyLocationListener()); //初始化SDK SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); mapView = (MapView) findViewById(R.id.bmpView); baiduMap = mapView.getMap(); baiduMap.setMyLocationEnabled(true); //尝试在监听按钮之前进行权限的允许 List<String> permissionList = new ArrayList<>(); if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION); } if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { permissionList.add(Manifest.permission.READ_PHONE_STATE); } if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (!permissionList.isEmpty()) { String[] permission = permissionList.toArray(new String[permissionList.size()]); ActivityCompat.requestPermissions(MainActivity.this, permission, 1); requestLocation(); } else { requestLocation(); } } private void requestLocation() { Log.i("MainActivity", "进入到requestLocation函数中"); initLocation(); //定位开始 initOrientationListener(); myOrientationListener.start(); mLocationClient.start(); } private void initLocation() { Log.i("MainActivity", "跳进了initLocation定位初始化函数中"); LocationClientOption option = new LocationClientOption(); option.setCoorType("bd09ll"); option.setScanSpan(1000); mLocationClient.setLocOption(option); } private void initOrientationListener() { Log.i("MainActivity", "跳进了initOrientationListener方向初始化函数中"); myOrientationListener = new MyOrientationListener(getApplicationContext()); myOrientationListener.setOnOrientationListener(new MyOrientationListener.OnOrientationListener() { @Override public void onOrientationChanged(float x) { mXDirection = (int) x; } }); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { Log.i("MainActivityActivity","进入onRequestPermissionResult函数中"); switch (requestCode) { case 1: if (grantResults.length > 0) { for (int result : grantResults) { if (result != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "必须同意所有权限", Toast.LENGTH_LONG).show(); finish(); return; } } // sendRequestWithOkHttp(); } else { Toast.makeText(this, "发生未知错误", Toast.LENGTH_LONG).show(); finish(); } break; default: } } //定位监听器的类 public class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { Log.i("MainActivity", "跳进了onReceiveLocation函数中"); if (location.getLocType() == BDLocation.TypeGpsLocation || location.getLocType() == BDLocation.TypeNetWorkLocation) { navigateTo(location); } } } private void navigateTo(BDLocation location) { Log.i("MainActivity", "跳进了navigateTo函数中"); //从服务器上获取实时的硬件位置 sendRequestWithOkHttp(); //将获取到的数据进行解析 ObjectJson(responseData); //将获取到的经纬度信息在地图上进行显示 displayLocation(dvalueX, dvalueY); //初次定位确定缩放尺寸,后面不改变便于手动伸缩 if (isFirstLocate) { BitmapDescriptor myBitMap = BitmapDescriptorFactory.fromResource(R.drawable.icon_reddirection); MyLocationConfiguration myLocationConfiguration = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, myBitMap); baiduMap.setMyLocationConfiguration(myLocationConfiguration); LatLng la = new LatLng(location.getLatitude(), location.getLongitude()); MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(la); baiduMap.animateMapStatus(update); update = MapStatusUpdateFactory.zoomTo(18f); baiduMap.animateMapStatus(update); isFirstLocate = false; } //将手机当前位置的小蓝点显示在屏幕上 MyLocationData.Builder locationBuilder = new MyLocationData.Builder(); locationBuilder.latitude(location.getLatitude()); locationBuilder.longitude(location.getLongitude()); //将要执行获取方向方法 locationBuilder.direction(mXDirection); MyLocationData locationData = locationBuilder.build(); baiduMap.setMyLocationData(locationData); } //重写三个方法以对mapView进行管理,保证资源可以及时释放 @Override protected void onResume() { Log.i("MainActivity", "进入到onResume函数中"); super.onResume(); mapView.onResume(); } @Override protected void onPause() { Log.i("MainActivity", "进入到onPause函数中"); super.onPause(); mapView.onPause(); } @Override protected void onDestroy() { Log.i("MainActivity", "进入到onDestroy函数中"); super.onDestroy(); mapView.onDestroy(); baiduMap.setMyLocationEnabled(false); mLocationClient.stop(); //停止方向监听 myOrientationListener.stop(); } private void sendRequestWithOkHttp() { Log.i("MainActivity", "跳进了sendRequestWithOkHttp方法中"); new Thread(new Runnable() { @Override //重写run方法,run方法规定了该线程的具体使命 public void run() { Log.i("MainActivity","跳进OkHttp的子线程中"); try { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://huadiheal.cn/animal/latest_data") .build(); Response response = client.newCall(request).execute(); responseData = response.body().string(); // ObjectJson(responseData); } catch (Exception e) { e.printStackTrace(); } } //创建后线程仅是占有内存资源,在JVM管理的线程中还没有这个资源,要调用父类的start方法通知JVM }).start(); } private void ObjectJson(String responseData) { Log.i("MainActivity", "跳进了ObjectJson函数中"); try { JSONObject jsonObject = new JSONObject(responseData); JSONObject valueX = jsonObject.getJSONObject("value_x"); JSONObject valueY = jsonObject.getJSONObject("value_y"); Iterator<String> iteratorX = valueX.keys(); while (iteratorX.hasNext()) { String valueXkey = iteratorX.next(); String valueXValue = valueX.getString(valueXkey); String valueYValue = valueY.getString(valueXkey); dvalueX = Double.parseDouble(valueXValue); dvalueY = Double.parseDouble(valueYValue); } } catch (Exception e) { e.printStackTrace(); } } public void displayLocation(double dvalueX, double dvalueY) { Log.i("MainActivity", "进入displayLocation中"); LatLng latLng = new LatLng(dvalueY, dvalueX); //进行坐标转换 CoordinateConverter converter = new CoordinateConverter() .from(CoordinateConverter.CoordType.GPS) .coord(latLng); LatLng dLatlng = converter.convert(); //进行刷新时,先清除上一次的overlay baiduMap.clear(); //现添加Marker将位置在地图上标出来 BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_niu32); OverlayOptions option = new MarkerOptions() .position(dLatlng) .icon(bitmap); baiduMap.addOverlay(option); } } ``` 方向传感器的监听类如下: ``` package com.example.gsontest; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.util.Log; //方向监听器的类 public class MyOrientationListener implements SensorEventListener { private SensorManager mySensorManager; private Sensor mySensor; private Context myContext; private float lastX; private OnOrientationListener myOnOrientationListener; public void start(){ Log.i("MainActivity", "跳进了方向类的start函数中"); mySensorManager = (SensorManager) myContext.getSystemService(Context.SENSOR_SERVICE); if(mySensorManager!=null){ mySensor = mySensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); } if(mySensor!=null){ //SENSOR_UI可能会出现数据滞后现象,若后期数据滞后则改成别的类型 mySensorManager.registerListener(this,mySensor,SensorManager.SENSOR_DELAY_NORMAL); } } //接触注册方向传感器监听事件,即对onDestroy中所引方法的实现 public void stop(){ Log.i("MainActivity","跳进方向类的stop函数中"); mySensorManager.unregisterListener(this); } //方向传感器的一个构造函数 public MyOrientationListener(Context myContext){ this.myContext = myContext; } @Override public void onAccuracyChanged(Sensor sensor,int accuracy){} //监听方向变化 @Override public void onSensorChanged(SensorEvent event){ Log.i("MainActivity","跳进了onSensorChanged函数中"); if(event.sensor.getType()==Sensor.TYPE_ORIENTATION){ float x = event.values[SensorManager.DATA_X]; if (Math.abs(x-lastX)>1.0){ if(myOnOrientationListener!=null){ myOnOrientationListener.onOrientationChanged(lastX); } } lastX = x; } } public void setOnOrientationListener(OnOrientationListener myOrientationListener){ this.myOnOrientationListener = myOrientationListener; } public interface OnOrientationListener{ void onOrientationChanged(float x); } } ``` 恳请大神帮忙看下程序谢谢!!
新手学android,监听两个按钮的问题,出现错误
package com.example.xingpengfei.guessnumber; import android.content.DialogInterface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.util.Random; public class MainActivity extends AppCompatActivity { private int number; private Button button1; private Button button2; private EditText editText; private void testRandom() { Random random=new Random(); number=random.nextInt(100); } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); testRandom(); button1=(Button)findViewById(R.id.button1); button2=(Button)findViewById(R.id.button2); editText=(EditText)findViewById(R.id.edit_text); button1.setOnClickListener(this); button2.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()){ case R.id.button1: //String input=editText.getText().toString(); int input=0; if(input==number) Toast.makeText(MainActivity.this,"恭喜你猜对了!",Toast.LENGTH_SHORT).show(); else if(input>number) Toast.makeText(MainActivity.this,"您猜的数字偏大!",Toast.LENGTH_SHORT).show(); else Toast.makeText(MainActivity.this,"您猜的数字偏小!",Toast.LENGTH_SHORT).show(); break; case R.id.button2: testRandom(); break; default: break; } } } 这是完整代码 在 button1.setOnClickListener(this); button2.setOnClickListener(this); 这里的this报错,请指教该如何改?
自己做了一个接收发送短信的练习,但是一点发送按钮就报错,也接收不了信息。求大神
![报错信息](https://img-ask.csdn.net/upload/201510/28/1446043535_542612.png) ![ui****](https://img-ask.csdn.net/upload/201510/28/1446043651_502014.png) **帮帮小弟,良辰必有重谢!!!targetSDK23,minSDK18** package com.example.think.smstest; import android.annotation.TargetApi; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Build; 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.telephony.SmsManager; import android.telephony.SmsMessage; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private TextView sender, content; private MessageReceiver messageReceiver; private SendStatusReceiver sendStatusReceiver; private IntentFilter intentFilter, sendFilter; private EditText to, msgInput; private Button send; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); sender = (TextView) findViewById(R.id.sender); content = (TextView) findViewById(R.id.content); intentFilter = new IntentFilter(); intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED"); messageReceiver = new MessageReceiver(); registerReceiver(messageReceiver, intentFilter); to = (EditText) findViewById(R.id.to); msgInput = (EditText) findViewById(R.id.msg_input); sendFilter = new IntentFilter(); sendFilter.addAction("SENT_SMS_ACTION"); sendStatusReceiver = new SendStatusReceiver(); registerReceiver(sendStatusReceiver, sendFilter); send = (Button) findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SmsManager smsManager = SmsManager.getDefault(); Intent intent = new Intent("SENT_SMS_ACTION"); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); smsManager.sendTextMessage(to.getText().toString(), null, msgInput.getText().toString(), pendingIntent, null); } }); } class MessageReceiver extends BroadcastReceiver { @TargetApi(Build.VERSION_CODES.M) @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i=0; i<messages.length; i++){ messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i],null); } String address = messages[0].getOriginatingAddress(); String fullMessage = ""; for (SmsMessage message : messages) { fullMessage += message.getMessageBody(); } sender.setText(address); content.setText(fullMessage); } } class SendStatusReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (getResultCode() == RESULT_OK) { Toast.makeText(context, "send succeed", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "send failed", Toast.LENGTH_SHORT).show(); } } } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(messageReceiver); unregisterReceiver(sendStatusReceiver); } }
android socket问题
package com.example.zzb; import android.support.v7.app.ActionBarActivity; import android.text.format.Time; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.Socket; import com.example.zzb.MainActivity; import android.app.Activity; import android.content.Intent; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView imageView = null; private Bitmap bmp = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.imageView1); Button btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { Thread t = new Thread() { @Override public void run() { super.run(); Socket socket = null; try { socket = new Socket("192.168.191.1", 33336); DataInputStream dataInput = new DataInputStream( socket.getInputStream()); int size = dataInput.readInt(); byte[] data = new byte[size]; // dataInput.readFully(data); int len = 0; while (len < size) { len += dataInput.read(data, len, size - len); } ByteArrayOutputStream outPut = new ByteArrayOutputStream(); bmp = BitmapFactory.decodeByteArray(data, 0, data.length); bmp.compress(CompressFormat.PNG, 100, outPut); /*AssetManager am = null; am = getAssets(); InputStream is = am.open("R.raw.a"); //imageView.setImageBitmap(); */ savePicture(bmp); myHandler.obtainMessage().sendToTarget(); } catch (IOException e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } }; t.start(); } }); } public void savePicture(Bitmap bitmap) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { try { File sdcardDir = Environment .getExternalStorageDirectory(); Time t = new Time(); t.setToNow(); String filename = sdcardDir.getCanonicalPath() + "/DCIM/camera" + String.format( "/ReeCam%04d%02d%02d%02d%02d%02d.jpg", t.year, t.month + 1, t.monthDay, t.hour, t.minute, t.second); File file = new File(filename); FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } private Handler myHandler = new Handler(){ public void handleMessage(android.os.Message msg) { imageView.setImageBitmap(bmp); }; }; } 这是一个从网上找的代码,然后自己改了就能用了。 我想把这个变一下,变成不用onclick,就是电脑上通过socket发送图片过来,手机自动就能接收并保存到手机上,不用再来一张图片必须点击一下button按钮。 不知道怎么改,试过去掉OnClickListener,然后就发现只能接收第一张图片,后面想接收第二张,必须把应用后台一下,再进入才能接收第二张。 本人安卓小白,希望能得到解决方案。谢谢大家了
此程序运行后界面闪退,求解答谢谢
MainAcitivity如下; package com.example.demo2; import android.app.ActionBar; import android.app.Activity; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private ActionBar actionBar ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.homepage_actionbar); actionBar = this.getActionBar(); initActionBar(); updateActionBar(); } private void initActionBar() { Resources r = getResources(); Drawable myDrawable = r.getDrawable(R.drawable.bar_bg); actionBar = getActionBar(); actionBar.setBackgroundDrawable(myDrawable);//定义背景色 actionBar.setDisplayHomeAsUpEnabled(true); //设置返回按钮是否可用 actionBar.setDisplayShowCustomEnabled(true);//设置home区图标是否显示 setTitle("课程中心");//设置Home区标题 } // // private void updateActionBar() { actionBar.setCustomView(R.layout.homepage_actionbar);//设置actionbar自定义布局 View userHomeActionBarView = actionBar.getCustomView();//获取该布局 //动态设置布局组件,定义按钮的点击事件 Button searchButton = (Button)userHomeActionBarView.findViewById(R.id.userhomepage_search_btn); TextView textView = (TextView)userHomeActionBarView.findViewById(R.id.title); textView.setText("7"); searchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this,"你点击了按钮", Toast.LENGTH_SHORT).show(); } }); } } Xml文件(homepage_actionbar)如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="10dip" android:layout_centerVertical="true" android:textColor="#FF0000" android:textSize="14dip" /> <ImageView android:id="@+id/inform_title_img" android:layout_width="80px" android:layout_height="80px" android:layout_toLeftOf="@+id/inform_title" android:layout_marginRight="5dip" android:layout_centerVertical="true" android:src="@drawable/inform"/> <TextView android:id="@+id/page_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:text="课程中心" android:textColor="#ffffff" android:textSize="16dip" /> <Button android:id="@+id/userhomepage_search_btn" android:layout_width="60px" android:layout_height="60px" android:layout_above="@+id/inform_title_img" android:layout_marginBottom="40dp" android:layout_marginRight="74dp" android:layout_toLeftOf="@+id/title" android:background="@drawable/search" android:textColor="#ffffff" android:textSize="12sp" /> </RelativeLayout> 程序在手机上运行就闪退,求解答,谢谢
为什么我开发的android计算器只能计算一次,求高手指点!
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/txtResult" android:layout_width="296px" android:layout_height="60px" android:background="#ffffffff" android:text="0.0" android:textSize="25sp" android:textStyle="bold" android:textColor="#ff333333" android:layout_x="11dp" android:layout_y="16dp" android:gravity="right" android:padding="2px"/> <Button android:id="@+id/btn1" android:layout_width="60px" android:layout_height="60px" android:text="1" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="15dp" android:layout_y="85dp" android:onClick="digital_click"/> <Button android:id="@+id/btn2" android:layout_width="60px" android:layout_height="60px" android:text="2" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="85dp" android:layout_y="85dp" android:onClick="digital_click"/> <Button android:id="@+id/btn3" android:layout_width="60px" android:layout_height="60px" android:text="3" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="155dp" android:layout_y="85dp" android:onClick="digital_click" /> <Button android:id="@+id/btnAdd" android:layout_width="80px" android:layout_height="60px" android:text="+" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="225dp" android:layout_y="85dp" android:onClick="add" /> <Button android:id="@+id/btn4" android:layout_width="60px" android:layout_height="60px" android:text="4" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="15dp" android:layout_y="155dp" android:onClick="digital_click" /> <Button android:id="@+id/btn5" android:layout_width="60px" android:layout_height="60px" android:text="5" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="85dp" android:layout_y="155dp" android:onClick="digital_click" /> <Button android:id="@+id/btn6" android:layout_width="60px" android:layout_height="60px" android:text="6" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="155dp" android:layout_y="155dp" android:onClick="digital_click" /> <Button android:id="@+id/btnsub" android:layout_width="80px" android:layout_height="60px" android:text="-" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="225dp" android:layout_y="155dp" android:onClick="sub" /> <Button android:id="@+id/btn7" android:layout_width="60px" android:layout_height="60px" android:text="7" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="15dp" android:layout_y="225dp" android:onClick="digital_click" /> <Button android:id="@+id/btn8" android:layout_width="60px" android:layout_height="60px" android:text="8" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="85dp" android:layout_y="225dp" android:onClick="digital_click" /> <Button android:id="@+id/btn9" android:layout_width="60px" android:layout_height="60px" android:text="9" android:textSize="20sp" android:background="#ff00ff99" android:textStyle="bold" android:gravity="center" android:layout_x="155dp" android:layout_y="225dp" android:onClick="digital_click" /> <Button android:id="@+id/btnMul" android:layout_width="80px" android:layout_height="60px" android:text="*" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="225dp" android:layout_y="225dp" android:onClick="mul" /> <Button android:id="@+id/btn0" android:layout_width="130px" android:layout_height="60px" android:text="0" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="15dp" android:layout_y="295dp" android:onClick="digital_click" /> <Button android:id="@+id/btnpoint" android:layout_width="60px" android:layout_height="60px" android:text="." android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="155dp" android:layout_y="295dp" android:onClick="point_click" /> <Button android:id="@+id/btnDiv" android:layout_width="80px" android:layout_height="60px" android:text="/" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="225dp" android:layout_y="295dp" android:onClick="div" /> <Button android:id="@+id/btndel" android:layout_width="60px" android:layout_height="60px" android:text="DE&gt;" android:textSize="20sp" android:textColor="#ffff3333" android:textStyle="bold" android:gravity="center" android:layout_x="15dp" android:layout_y="365dp" android:onClick="del" /> <Button android:id="@+id/btnequ" android:layout_width="220px" android:layout_height="60px" android:text="=" android:textSize="20sp" android:textStyle="bold" android:gravity="center" android:layout_x="85dp" android:layout_y="365dp" android:onClick="equ" /> </AbsoluteLayout> package com.example.jishuanqi; import java.text.NumberFormat; import java.util.Formatter; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { //第一个输入的数据 double a=0; //记录第一次输入的符号 char b='+'; StringBuffer c=new StringBuffer();//得到textview中的数据 boolean d=false;//第一个数据是否是小数点 TextView txtResult;//输出结果 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtResult=(TextView)findViewById(R.id.txtResult); } /* * 对数据进行初始化 * (non-Javadoc) * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) */ public void init(){ c.delete(0, c.length());//设置当前textView中的值为0 d=false; } //将输入的数据转换成double类型 public double stringToDouble(){ if(c.length()==0){ //如果没有输入的数据 return 0; } double result=Double.parseDouble(c.toString()); return result; } //进行计算处理 public double calcu(){ double result=0; switch(b){ case '+': result=a+stringToDouble(); break; case '-': result=a-stringToDouble(); break; case '*': result=a*stringToDouble(); break; case '/': result=a/stringToDouble(); break; } //对小数点后的数据进行格式化 NumberFormat format=NumberFormat.getInstance(); format.setMaximumFractionDigits(2); result=Double.parseDouble(format.format(result)); return result; } //显示数据 public void display(){ txtResult.setText(c.toString()); } //处理数据按钮的点击 public void digital_click(View view){ Button btnDigital=(Button) view; char text=btnDigital.getText().charAt(0); c.append(text); display(); } //处理 加法 public void add(View view){ double result=calcu(); txtResult.setText(String.valueOf(result)); a=result; b='+'; init(); } //处理减法 public void sub(View view){ double result=calcu(); txtResult.setText(String.valueOf(result)); a=result; b='-'; init(); } //处理乘法 public void mul(View view){ double result=calcu(); txtResult.setText(String.valueOf(result)); a=result; b='*'; init(); } //处理除法 public void div(View view){ double result=calcu(); txtResult.setText(String.valueOf(result)); a=result; b='/'; init(); } //处理等于 public void equ(View view){ double result=calcu(); txtResult.setText(String.valueOf(result)); a=result; b='='; init(); } //处理小数点 public void point_click(View view){ if(d){ //当一个数据为小数点时程序返回 return; } if(c.length()==0){ //当没有输入的数据时返回 return; } Button btnPoint=(Button) view; char text=btnPoint.getText().charAt(0); c.append(text); d=true; display(); } //处理删除数据 public void del(View view){ if(c.length()>=1){ c.delete(c.length()-1, c.length()); } if(c.length()==0){ init(); display(); } txtResult.setText(c); } }
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入  假设现有4个人
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
【图解经典算法题】如何用一行代码解决约瑟夫环问题
约瑟夫环问题算是很经典的题了,估计大家都听说过,然后我就在一次笔试中遇到了,下面我就用 3 种方法来详细讲解一下这道题,最后一种方法学了之后保证让你可以让你装逼。 问题描述:编号为 1-N 的 N 个士兵围坐在一起形成一个圆圈,从编号为 1 的士兵开始依次报数(1,2,3…这样依次报),数到 m 的 士兵会被杀死出列,之后的士兵再从 1 开始报数。直到最后剩下一士兵,求这个士兵的编号。 1、方
致 Python 初学者
文章目录1. 前言2. 明确学习目标,不急于求成,不好高骛远3. 在开始学习 Python 之前,你需要做一些准备2.1 Python 的各种发行版2.2 安装 Python2.3 选择一款趁手的开发工具3. 习惯使用IDLE,这是学习python最好的方式4. 严格遵从编码规范5. 代码的运行、调试5. 模块管理5.1 同时安装了py2/py35.2 使用Anaconda,或者通过IDE来安装模
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
      11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下
日均350000亿接入量,腾讯TubeMQ性能超过Kafka
整理 | 夕颜出品 | AI科技大本营(ID:rgznai100) 【导读】近日,腾讯开源动作不断,相继开源了分布式消息中间件TubeMQ,基于最主流的 OpenJDK8开发的
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法不过,当我看了源代码之后这程序不到50
相关热词 如何提升c#开发能力 矩阵乘法c# c#调用谷歌浏览器 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天
立即提问