单击下一个按钮时,android GPS第二活动错误

如何解决单击下一个按钮时,android GPS第二活动错误

|
enter code here
   05-30 22:54:51.245: ERROR/AndroidRuntime(1383): FATAL EXCEPTION: main
    05-30 22:54:51.245: ERROR/AndroidRuntime(1383): java.lang.IllegalStateException: Could not find a method appendText(View) in the activity class yaraby.y.yarab for onClick handler on view class android.widget.Button with id \'enter\'
    05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.view.View$1.onClick(View.java:2059)
   05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.view.View.performClick(View.java:2408)
  05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.view.View$PerformClick.run(View.java:8816)
  05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.os.Handler.handleCallback(Handler.java:587)
  05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.os.Handler.dispatchMessage(Handler.java:92)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.os.Looper.loop(Looper.java:123)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.app.ActivityThread.main(ActivityThread.java:4633)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at java.lang.reflect.Method.invokeNative(Native Method)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at java.lang.reflect.Method.invoke(Method.java:521)
05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at dalvik.system.NativeStart.main(Native Method)
05-30 22:54:51.245: ERROR/AndroidRuntime(1383): Caused by: java.lang.NoSuchMethodException: appendText
05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at java.lang.Class.getMethod(Class.java:985)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     at android.view.View$1.onClick(View.java:2052)
 05-30 22:54:51.245: ERROR/AndroidRuntime(1383):     ... 11 more
亚拉比课程
enter code here

   public class yaraby extends Activity {
/** Called when the activity is first created. */
String sentence,sentence1,modifiedSentence;;
EditText inputfld,txt;
TextView Text;
Button Enter,Connect,next;
Socket clientSocket;

DataOutputStream outToServer;
BufferedReader inFromServer ;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    inputfld=(EditText)findViewById(R.id.input);
    Text=(TextView)findViewById(R.id.view);
    Enter=(Button)findViewById(R.id.enter);
    Connect=(Button)findViewById(R.id.connect);

    Text.append( \"\\n about to create a socket\");    


    txt=(EditText)findViewById(R.id.txt);
    next = (Button) findViewById(R.id.Button01);   

    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try{
            Intent i = new Intent(yaraby.this,yarab.class);
            startActivity(i);
            }
            catch(Error e){
                Log.e(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",e.getMessage());
            }

        }});

                  }





public void appendText(View view){
    Text.append( \"\\n  In chat \");

    try{

    sentence=inputfld.getText().toString();
    sentence1=\"ingyyyy\";
    Text.append( \"\\n  DataStream creating\");        
    outToServer.writeBytes(sentence);
    outToServer.writeBytes(sentence1);
    Thread.sleep(1000);
    modifiedSentence = inFromServer.readLine(); 
    Text.append(modifiedSentence);
    inputfld.setText(null);

    }
    catch(Exception modifiedsentence){
        Text.append(\"Exception\");
    }


}


public void connect(View view){
    try{
        clientSocket= new Socket(\"192.168.1.6\",54611); 
        Text.append( \"\\n created a socket\");
        outToServer = new DataOutputStream(clientSocket.getOutputStream());
        Text.append( \"\\n created a datastream\");
        inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        Text.append( \"\\n created a bufferReader\");
        outToServer = new DataOutputStream(clientSocket.getOutputStream());


           }catch(Exception e){
        System.out.println(\"Error\");
         }
                }

enter code here

  public class yarab extends MapActivity

            {
     Socket clientSocket;
      TextView Text; 
private MapView mapView;
private MapController mc;
     DataOutputStream outToServer;            
    BufferedReader inFromServer ;

int error = 50;
GeoPoint p,p2;
List<Overlay> mapOverlays;
Drawable drawable,drawable;
HelloItemizedOverlay itemizedOverlay,itemizedOverlay2;

LocationManager locationManager;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState)

{
    try {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        /* Use the LocationManager class to obtain GPS locations */

        LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        LocationListener mlocListener = new MyLocationListener();

        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,mlocListener);
        mapView = (MapView) findViewById(R.id.mapView);

        // enable Street view by default
        mapView.setStreetView(true);

        // enable to show Satellite view
        mapView.setSatellite(true);

        // enable to show Traffic on map
        // mapView.setTraffic(true);
        mapView.setBuiltInZoomControls(true);

        mc = mapView.getController();
        // mapView.setStreetView(true);
        // mapView.setSatellite(true);
        mc.setZoom(12);
        addOverLays();
       } catch (Exception e) {
        Log.d(\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",e.getMessage());
    }

}


public void addOverLays() {
    String[] coordinates = { \"31.216487288475037\",\"29.932637214660645\",\"30.084123015403748\",\"51.5002\",\"-0.1262\",\"31.337149143218994\" };
    //lat10=29.97885355949402,lat11=29.98787991531372,lat12=29.98787991531372;

    double lat = 29.98739718380868,lat2 = 29.987810254096985;
    double log = 31.442527770886084,log2 = 31.44258677959442;
    p = new GeoPoint((int) (lat * 1E6),(int) (log * 1E6));
    p2 = new GeoPoint((int) (lat2 * 1E6 ),(int) (log2 * 1E6 ));


    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.wit);
    drawable2 = this.getResources().getDrawable(R.drawable.ballon);
;
        itemizedOverlay17 = new HelloItemizedOverlay(drawable17,this);
        itemizedOverlay15 = new HelloItemizedOverlay(drawable15,this);
        itemizedOverlay16 = new HelloItemizedOverlay(drawable16,this);
    itemizedOverlay = new HelloItemizedOverlay(drawable,this);
    itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);

    OverlayItem overlayitem = new OverlayItem(p,\"Cairo\",\" over1\");
    OverlayItem over2 = new OverlayItem(p2,\"ulm\",\"over2\");


    itemizedOverlay.addOverlay(overlayitem);

    mapOverlays.add(itemizedOverlay);

    itemizedOverlay2.addOverlay(over2);
    mapOverlays.add(itemizedOverlay2);




}






public void Location(){



    LocationManager myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);


    LocationListener mlocListener1 = new MyLocationListener();

    LocationManager mlocManager1 = null;
    mlocManager1.requestLocationUpdates(LocationManager.GPS_PROVIDER,mlocListener1);
        //  Get the current location in start-up
          GeoPoint initGeoPoint = new GeoPoint((int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
       .getLatitude()*1000000),(int)(myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude()*1000000));
       mc.animateTo(initGeoPoint);
    mc.setZoom(16);

    drawable21 = this.getResources().getDrawable(R.drawable.ggg);
    itemizedOverlay21 = new HelloItemizedOverlay(drawable21,this);
    OverlayItem over21 = new OverlayItem(initGeoPoint,\"offff\",\"over21\");

    itemizedOverlay21.addOverlay(over21);
    mapOverlays.add(itemizedOverlay21);
}


/* Class My Location Listener */

public class MyLocationListener implements LocationListener

{

    @Override
    public void onLocationChanged(Location loc)

    {

        GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),(int) (loc.getLongitude() * 1E6));



        String Text = \"My current location is: \" +

        \"Latitud =\" + loc.getLatitude()+ 

        \"Longitud =\" +loc.getLongitude() ;// loc.getLongitude() ; //loc.getLatitude()+\"anoog\" + (p3.getLatitudeE6() - error)

        Toast.makeText(getApplicationContext(),Text,Toast.LENGTH_SHORT).show();


    mc.animateTo(point);

    }


    private Resources getResources() {
        // TODO Auto-generated method stub
        return null;
    }


    public void onProviderDisabled(String provider)

    {

        Toast.makeText(getApplicationContext(),\"Gps Disabled\",Toast.LENGTH_SHORT).show();

    }

    public void onProviderEnabled(String provider)

    {

        Toast.makeText(getApplicationContext(),\"Gps Enabled\",Toast.LENGTH_SHORT).show();

    }

    public void onStatusChanged(String provider,int status,Bundle extras)

    {

    }

    protected boolean isRouteDisplayed() {
        return false;
    }

}/* End of Class MyLocationListener */

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

       }
这是mainfaist
enter code here
  <?xml version=\"1.0\" encoding=\"utf-8\"?>
<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />
<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />    

<application android:icon=\"@drawable/icon\" android:label=\"@string/app_name\">
    <activity android:name=\".yaraby\"
              android:label=\"@string/app_name\">
        <intent-filter>
            <action android:name=\"android.intent.action.MAIN\" />
            <category android:name=\"android.intent.category.LAUNCHER\" />
        </intent-filter>
    </activity>

<activity android:name=\".Mapy\"
              android:label=\"@string/app_name\">
        <intent-filter>
              <action android:name=\"android.intent.action.VIEW\" />
            <category android:name=\"android.intent.category.DEFAULT\" />
        </intent-filter>
    </activity>

<activity android:name=\".HelloItemizedOverlay\"
              android:label=\"@string/app_name\">
        <intent-filter>
           <action android:name=\"android.intent.action.VIEW\" />
            <category android:name=\"android.intent.category.DEFAULT\" />
        </intent-filter>
    </activity>
</application>
    

解决方法

        您的问题在
yarab.onCreate()
方法中:
   } catch (Exception e) {
    Log.d(\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",e.getMessage());
}
e.getMessage()
返回空,
Log.d
不喜欢空消息。尝试改用
e.toString()
。一些例外仅包含空消息。     ,        e.getMessage()返回null吗? 尝试:
...
} catch (Exception e) {
  e.printStackTrace();
}
在onCreate方法的最后(第105行)     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-