小编joh*_*ker的帖子

方法getApplicationContext()未定义

public void onProviderDisabled(String provider) {
    Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT);


}
Run Code Online (Sandbox Code Playgroud)

所以这就是我所拥有的,并且它显示了一个错误,并告诉我方法getApplicationContext()未定义类型MyLocationListener

我该怎么做才能避免这个错误

android

16
推荐指数
1
解决办法
5万
查看次数

java.lang.SecurityException"gps"位置提供程序需要ACCESS_FINE_LOCATION权限

所以这是我的MyLocationListener类

package com.example.gpslocater;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class MyLocationListener implements LocationListener {

        public TextView mLocationTextView;
    Context mContent;
    public MyLocationListener(Context context) {
        mContent = context;
    }
    @Override
    public void onLocationChanged(Location location) {

        location.getLatitude();
        location.getLongitude();

        String Text = "My current location is :" + 
        "Latitude = " + location.getLatitude() +
        " Longitude = " + location.getLongitude();
        //figure out a way to make it display through a text view
        mLocationTextView.setText(Text);
    }

    @Override
    public void …
Run Code Online (Sandbox Code Playgroud)

android

6
推荐指数
1
解决办法
2万
查看次数

错误:找不到与给定名称匹配的资源

在此文件中,我的布局在此代码中显示以下错误

error: Error: No resource found that matches the given name (at 'id' with value '@id/question_text_view').
error: Error: No resource found that matches the given name (at 'id' with value '@id/next_button').
Run Code Online (Sandbox Code Playgroud)

这是布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        />
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >
        <Button 
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/true_button"
        />
        <Button 
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"
        />
    </LinearLayout>
        <Button 
        android:id="@id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"
        />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <resources>

        <string name="app_name">GeoQuiz</string>
        <string name="true_button">True</string> …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
8966
查看次数

标签 统计

android ×3