我经常使用这个页面来解决我的问题,这是我第一次问,所以我会提前抱歉,感谢你的帮助!
我第一次使用RecicleView,admob和Lists,应用程序崩溃了,我整夜都在寻找bug,但我无法找到它。
我的错误输出如下:
03-26 08:19:29.303 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/mpeg-L1
03-26 08:19:29.303 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/mpeg-L2
03-26 08:19:29.313 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/x-ms-wma
03-26 08:19:29.313 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/x-ima
03-26 08:19:29.313 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/qcelp
03-26 08:19:29.323 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/evrc
03-26 08:19:29.333 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/wvc1
03-26 08:19:29.333 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/x-ms-wmv
03-26 08:19:29.343 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es
03-26 08:19:29.343 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/wvc1
03-26 08:19:29.353 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/x-ms-wmv
03-26 08:19:29.353 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/x-ms-wmv7
03-26 08:19:29.353 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/x-ms-wmv8
03-26 08:19:29.353 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/mp43
03-26 08:19:29.363 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/sorenson
03-26 08:19:29.383 3849-4076/app.synchronice.com.admobtutorial W/VideoCapabilities: Unsupported mime video/mp4v-esdp
03-26 08:19:29.433 3849-4076/app.synchronice.com.admobtutorial I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
03-26 08:19:29.453 3849-4076/app.synchronice.com.admobtutorial W/AudioCapabilities: Unsupported mime audio/ac3
03-26 08:19:29.533 3849-3849/app.synchronice.com.admobtutorial I/Ads: Starting ad request.
03-26 08:19:29.613 3849-3849/app.synchronice.com.admobtutorial I/BrokersActivity: A3. Add in mBottomBanner
03-26 08:19:29.613 3849-3849/app.synchronice.com.admobtutorial I/BrokersActivity: A4. mBrokersList
03-26 08:19:29.683 3849-3856/app.synchronice.com.admobtutorial W/art: Suspending all threads took: 51.666ms
03-26 08:19:29.693 3849-3849/app.synchronice.com.admobtutorial I/BrokersActivity: A5. Añado todo a la mBrokersList
03-26 08:19:29.783 3849-3849/app.synchronice.com.admobtutorial I/BrokersActivity: A6. setSupportActionBar(mToolbar);
03-26 08:19:29.783 3849-3849/app.synchronice.com.admobtutorial I/BrokersActivity: A7. SetOnClickListener
03-26 08:19:29.913 3849-4086/app.synchronice.com.admobtutorial I/WebViewFactory: Loading com.google.android.webview version 56.0.2924.87 (code 292408700)
03-26 08:19:29.933 3849-3864/app.synchronice.com.admobtutorial I/art: Background sticky concurrent mark sweep GC freed 37551(3MB) AllocSpace objects, 24(893KB) LOS objects, 17% free, 21MB/25MB, paused 3.845ms total 133.666ms
03-26 08:19:29.973 3849-4120/app.synchronice.com.admobtutorial I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.25.03.06
Build Date: 01/24/15 Sat
Local Branch: AF11_RB1_AU15
Remote Branch:
Local Patches:
Reconstruct Branch:
03-26 08:19:30.013 3849-4120/app.synchronice.com.admobtutorial I/OpenGLRenderer: Initialized EGL, version 1.4
03-26 08:19:30.154 3849-3856/app.synchronice.com.admobtutorial W/art: Suspending all threads took: 22.094ms
03-26 08:19:30.164 3849-4086/app.synchronice.com.admobtutorial I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
03-26 08:19:30.164 3849-4086/app.synchronice.com.admobtutorial I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
03-26 08:19:30.204 3849-4086/app.synchronice.com.admobtutorial I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
03-26 08:19:30.254 3849-4086/app.synchronice.com.admobtutorial I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
03-26 08:19:30.394 3849-3849/app.synchronice.com.admobtutorial W/ResourceType: No package identifier when getting value for resource number 0x000186a0
03-26 08:19:30.474 3849-4086/app.synchronice.com.admobtutorial I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 1665-1671)
03-26 08:19:30.474 3849-4086/app.synchronice.com.admobtutorial I/cr_LibraryLoader: Expected native library version number "56.0.2924.87", actual native library version number "56.0.2924.87"
03-26 08:19:30.474 3849-3849/app.synchronice.com.admobtutorial E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.synchronice.com.admobtutorial, PID: 3849
android.content.res.Resources$NotFoundException: String resource ID #0x186a0
at android.content.res.Resources.getText(Resources.java:1334)
at android.widget.TextView.setText(TextView.java:4921)
at app.synchronice.com.admobtutorial.BrokerAdapter.onBindViewHolder(BrokerAdapter.java:55)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6356)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6389)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5335)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5598)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3312)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3844)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1077)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1391)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:16711)
at android.view.ViewGroup.layout(ViewGroup.java:5328)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2319)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2032)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Chore
App只有1个活动和2个类:
BrokersActivity.java(活动)
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.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class BrokersActivity extends AppCompatActivity {
private AdView mBottomBanner;
private Toolbar mToolbar;
private FloatingActionButton fab;
private RecyclerView mBrokersList;
private String TAG = "BrokersActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_brokers);
//DEBUG Log.d(TAG,"");
Log.i(TAG,"A1. setContentView(R.layout.activity_brokers)");
//Ui
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mBottomBanner = (AdView) findViewById(R.id.av_bottom_banner);
fab = (FloatingActionButton) findViewById(R.id.fab);
Log.i(TAG,"A2. mToolbar, mBottomBanner,fab");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("82E1680616B2F7473A2CF976AF978D28") //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mBottomBanner.loadAd(adRequest);
Log.i(TAG,"A3. Add in mBottomBanner");
mBrokersList = (RecyclerView) findViewById(R.id.brokers_list);
Log.i(TAG,"A4. mBrokersList");
BrokerAdapter brokersAdapter = new BrokerAdapter(
this,
Broker.FAKE_DATA_BROKERS,
new BrokerAdapter.BrokerItemClick() {
@Override
public void onBrokerClick(Broker clickedBroker) {
// Lógica
}
});
mBrokersList.setAdapter(brokersAdapter);
Log.i(TAG,"A5. Añado todo a la mBrokersList");
//Setup
setSupportActionBar(mToolbar);
Log.i(TAG,"A6. setSupportActionBar(mToolbar); ");
//SetOnClickListener
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();
}
});
Log.i(TAG,"A7. SetOnClickListener");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_brokers, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
//Controles de publicidad
@Override
protected void onResume() {
super.onResume();
if (mBottomBanner != null) {
mBottomBanner.resume();
}
}
@Override
protected void onPause() {
super.onPause();
if (mBottomBanner != null) {
mBottomBanner.pause();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mBottomBanner != null) {
mBottomBanner.destroy();
}
}
}
经纪人(班级)
public class Broker {
private String mId;
private String mName;
private String mDescription;
private String TAG = "Broker";
private int mUsersPerMonth;
@DrawableRes
private int mFeaturedImageResId;
public Broker(String name,
String description, int usersPerMonth,
@DrawableRes int featuredImageResId) {
this.mId = UUID.randomUUID().toString();
this.mName = name;
this.mDescription = description;
this.mUsersPerMonth = usersPerMonth;
this.mFeaturedImageResId = featuredImageResId;
}
public String getId() {
return mId;
}
public void setId(String mId) {
this.mId = mId;
}
public String getName() {
return mName;
}
public void setName(String mName) {
this.mName = mName;
}
public String getDescription() {
return mDescription;
}
public void setDescription(String mDescription) {
this.mDescription = mDescription;
}
public int getUsersPerMonth() {
return mUsersPerMonth;
}
public void setUsersPerMonth(int mUsersPerMonth) {
this.mUsersPerMonth = mUsersPerMonth;
}
public int getFeaturedImageResId() {
return mFeaturedImageResId;
}
public void setFeaturedImageResId(int mFeaturedImageResId) {
this.mFeaturedImageResId = mFeaturedImageResId;
}
public static List<Broker> FAKE_DATA_BROKERS = new ArrayList<>();
static {
FAKE_DATA_BROKERS.add(new Broker("Forex Mother of dragons",
"El mejor broker de forex, abre tu cuenta ya",
100000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Black Forex",
"Comienza con tan solo 50USD",
120000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Be Rich Now",
"Entrenate y duplica tu inversión",
1920000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Forexgump",
"Ve de 100USD a 4000USD en dos semanas",
900000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Dinero fácil pro",
"Olvidate de tu trabajo y abre una cuenta ahora mismo",
14000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Money money money!",
"Qué esperas?, invierte tu capital!",
100000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Invertsor",
"Operaciones forex de práctica",
40000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Forex Machine",
"Entra y descubre una estrategia nunca antes revelada",
30000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Forexme",
"Explota tu inversión",
220000, R.drawable.broker_forex_g));
FAKE_DATA_BROKERS.add(new Broker("Aprende algo dinero",
"De la mano de los mejores maestros del trading",
200000, R.drawable.broker_forex_g));
}
}
BrokerAdapter(class)
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
public class BrokerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context mContext;
private List<Broker> mItems = new ArrayList<>();
private BrokerItemClick mItemClickListener;
private String TAG = "BrokersAdapter";
public BrokerAdapter(Context context,
List<Broker> brokers,
BrokerItemClick brokerItemClick) {
mContext = context;
mItems = brokers;
mItemClickListener = brokerItemClick;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
switch (viewType) {
default:
view = layoutInflater
.inflate(R.layout.list_item_broker, parent, false);
return new BrokerViewHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Broker currentItem = mItems.get(position);
BrokerViewHolder brokerViewHolder = (BrokerViewHolder) holder;
brokerViewHolder.name.setText(currentItem.getName());
brokerViewHolder.description.setText(currentItem.getDescription());
brokerViewHolder.usersPerMonth.setText(currentItem.getUsersPerMonth()); //formatUsersPerMonth
Glide.with(mContext)
.load(currentItem.getFeaturedImageResId())
.centerCrop()
.into(brokerViewHolder.featuredImage);
}
@Override
public int getItemCount() {
return mItems.size();
}
public class BrokerViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public TextView name;
public TextView description;
public TextView usersPerMonth;
public ImageView featuredImage;
public BrokerViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.tv_name);
description = (TextView) itemView.findViewById(R.id.tv_description);
usersPerMonth = (TextView) itemView.findViewById(R.id.tv_users_per_month);
featuredImage = (ImageView) itemView.findViewById(R.id.tv_featured_image);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
int position = getAdapterPosition();
mItemClickListener.onBrokerClick(mItems.get(position));
}
}
interface BrokerItemClick {
void onBrokerClick(Broker clickedBroker);
}
}
再次提前感谢您!