'com.example.volleyexample.app.AppController' 不可分配给 'android.app.Activity'
'com.example.volleyexample.app.AppController' is not assignable to 'android.app.Activity'
不知道为什么会出现这个错误
遗漏的地方添加一些代码或删除代码。
我会尝试 JSon 对象请求
我要 2 class AppController
AND LruBitmapCache
Manifest.xml
的屏幕截图:
activity_main.xml :
<LinearLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
下面的代码是 AppController.java
class:
package com.example.volleyexample.app;
import android.app.Application;
import android.text.TextUtils;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.volleyexample.utils.LruBitmapCache;
public class AppController extends Application{
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
mImageLoader = new ImageLoader(this.mRequestQueue,
new LruBitmapCache());
}
return this.mImageLoader;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
提前致谢:)
您必须使用 Activity 名称 添加正确的包名称。
The name of the class that implements the activity, a subclass of
Activity. The attribute value should be a fully qualified class name
(such as, "com.example.project.ExtracurricularActivity"). However, as
a shorthand, if the first character of the name is a period (for
example, ".ExtracurricularActivity"), it is appended to the package
name specified in the element.
您应该添加 正确的包名称 Activity 名称 。
<activity android:name="yourPackageName.ActivityName
android:parentActivity姓名
The class name of the logical parent of the activity. The name here
must match the class name given to the corresponding
element's android:name
attribute.
注意
你的AppController是Application
class,所以应该是<application
部分.
终于
<application
android:name="com.example.volleyexample.app.AppController"
android:allowBackup="true"
>
<activity
android:name="
>
然后Clean-Rebuild-Run
.
应该在manifest的Application标签中。如下所示
<application
android:name=".yourPackage.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
// Your activities, services... declared here
</application>
不知道为什么会出现这个错误
遗漏的地方添加一些代码或删除代码。
我会尝试 JSon 对象请求
我要 2 class AppController
AND LruBitmapCache
Manifest.xml
的屏幕截图:
activity_main.xml :
<LinearLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
下面的代码是 AppController.java
class:
package com.example.volleyexample.app;
import android.app.Application;
import android.text.TextUtils;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.volleyexample.utils.LruBitmapCache;
public class AppController extends Application{
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
mImageLoader = new ImageLoader(this.mRequestQueue,
new LruBitmapCache());
}
return this.mImageLoader;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
提前致谢:)
您必须使用 Activity 名称 添加正确的包名称。
The name of the class that implements the activity, a subclass of Activity. The attribute value should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity"). However, as a shorthand, if the first character of the name is a period (for example, ".ExtracurricularActivity"), it is appended to the package name specified in the element.
您应该添加 正确的包名称 Activity 名称 。
<activity android:name="yourPackageName.ActivityName
android:parentActivity姓名
The class name of the logical parent of the activity. The name here must match the class name given to the corresponding element's
android:name
attribute.
注意
你的AppController是Application
class,所以应该是<application
部分.
终于
<application
android:name="com.example.volleyexample.app.AppController"
android:allowBackup="true"
>
<activity
android:name="
>
然后Clean-Rebuild-Run
.
应该在manifest的Application标签中。如下所示
<application
android:name=".yourPackage.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
// Your activities, services... declared here
</application>