安卓开发笔记——关于java.lang.RuntimeException: Unable to start activity ComponentInfo{......}问题的解决方案

笔者在实现一个消息上下轮播时,遇到APP闪退:

将日志打印出来:

Process: com.ghl.intelligence, PID: 6557  
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ghl.intelligence/com.ghl.intelligence.MainActivity}: android.view.InflateException:
 Binary XML file line #154: Error inflating class LooperTextView
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2435)    

具体内容为:

在这里插入图片描述 在这里插入图片描述

产生问题的就是LooperTextView:
在这里插入图片描述
在LooperTextView前面加上com.ghl.intelligence.即可成功解决:

 <com.ghl.intelligence.LooperTextView
                android:layout_marginTop="3dp"
                android:layout_marginBottom="3dp"
                android:id="@+id/looperview"
                android:layout_width="match_parent"
                android:layout_height="60px"
                android:layout_marginLeft="3dp"
                android:background="#00ffff">
                </com.ghl.intelligence.LooperTextView>

因为此处LooperTextView为开发者自定义的View,此处com.ghl.intelligence.为项目的包名

发布了20 篇原创文章 · 获赞 26 · 访问量 1万+
展开阅读全文

安卓开发java.lang.RuntimeException: Unable to start activity ComponentInfo问题

11-08

package com.example.test; import android.app.ActivityGroup; import android.app.LocalActivityManager; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @SuppressWarnings("deprecation") public class MainActivity extends ActivityGroup { // Tab Activity Layout private LocalActivityManager localActivityManager = null; private LinearLayout mainTabContainer = null; private Intent mainTabIntent = null; // Tab banner title private TextView mainTabTitleTextView = null; // Tab ImageView private ImageView appreciateImageView = null; private ImageView discussImageView = null; private ImageView identificationImageView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); appreciateImageView = (ImageView) super .findViewById(R.id.appreciate_tab_btn); mainTabContainer = (LinearLayout) findViewById(R.id.main_tab_banner_title); appreciateImageView.setImageResource(R.drawable.appreciate_press); discussImageView.setImageResource(R.drawable.discuss_normal); identificationImageView .setImageResource(R.drawable.identification_normal); localActivityManager = getLocalActivityManager(); mainTabTitleTextView = (TextView) findViewById(R.id.main_tab_banner_title); appreciateImageView = (ImageView) findViewById(R.id.appreciate_tab_btn); discussImageView = (ImageView) findViewById(R.id.discuss_tab_btn); identificationImageView = (ImageView) findViewById(R.id.identification_tab_btn); setContainerView("appreciate", AppreciateTabActivity.class); setContentView(R.layout.activity_main); initTab(); } /** * 初始化Tab项 */ private void initTab() { mainTabTitleTextView = (TextView) findViewById(R.id.main_tab_banner_title); appreciateImageView = (ImageView) findViewById(R.id.appreciate_tab_btn); discussImageView = (ImageView) findViewById(R.id.discuss_tab_btn); identificationImageView = (ImageView) findViewById(R.id.identification_tab_btn); appreciateImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { appreciateImageView .setImageResource(R.drawable.appreciate_press); discussImageView.setImageResource(R.drawable.discuss_normal); identificationImageView .setImageResource(R.drawable.identification_normal); setContainerView("appreciate", AppreciateTabActivity.class); mainTabTitleTextView.setText("欣赏美花"); } }); discussImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { appreciateImageView .setImageResource(R.drawable.appreciate_normal); discussImageView.setImageResource(R.drawable.discuss_press); identificationImageView .setImageResource(R.drawable.identification_normal); setContainerView("discuss", DiscussTabActivity.class); mainTabTitleTextView.setText("评花论花"); } }); identificationImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { appreciateImageView .setImageResource(R.drawable.appreciate_normal); discussImageView.setImageResource(R.drawable.discuss_normal); identificationImageView .setImageResource(R.drawable.identification_press); setContainerView("identification", IdentificationTabActivity.class); mainTabTitleTextView.setText("亮眼识花"); } }); } public void setContainerView(String id, Class<?> activity) { mainTabContainer.removeAllViews(); mainTabIntent = new Intent(this, activity); mainTabContainer.addView(localActivityManager.startActivity(id, mainTabIntent).getDecorView()); } } 出现如下错误:![CSDN移动问答][1] [1]: http://xiangce.baidu.com/picture/detail/a3296cfaddcb74077c4b6751e000a41f08316fc6?from=dialoghttp://xiangce.baidu.com/picture/detail/a3296cfaddcb74077c4b6751e000a41f08316fc6?from=dialog 问答

坐等解答:Unable to start activity ComponentInfo

04-13

程序手机运行OK,模拟器运行报错,求解答,贴出Logcat: 04-12 23:48:22.968: E/AndroidRuntime(1509): FATAL EXCEPTION: main 04-12 23:48:22.968: E/AndroidRuntime(1509): Process: com.gh.lighting, PID: 1509 04-12 23:48:22.968: E/AndroidRuntime(1509): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gh.lighting/com.gh.lighting.ui.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class com.gh.lighting.widget.GhViewPager 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread.access$800(ActivityThread.java:135) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.os.Handler.dispatchMessage(Handler.java:102) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.os.Looper.loop(Looper.java:136) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread.main(ActivityThread.java:5017) 04-12 23:48:22.968: E/AndroidRuntime(1509): at java.lang.reflect.Method.invokeNative(Native Method) 04-12 23:48:22.968: E/AndroidRuntime(1509): at java.lang.reflect.Method.invoke(Method.java:515) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 04-12 23:48:22.968: E/AndroidRuntime(1509): at dalvik.system.NativeStart.main(Native Method) 04-12 23:48:22.968: E/AndroidRuntime(1509): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class com.gh.lighting.widget.GhViewPager 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.createView(LayoutInflater.java:620) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.gh.lighting.widget.MainScreenFragment.onCreateView(MainScreenFragment.java:207) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.gh.lighting.ui.MainActivity.onStart(MainActivity.java:466) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.Activity.performStart(Activity.java:5241) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 04-12 23:48:22.968: E/AndroidRuntime(1509): ... 11 more 04-12 23:48:22.968: E/AndroidRuntime(1509): Caused by: java.lang.reflect.InvocationTargetException 04-12 23:48:22.968: E/AndroidRuntime(1509): at java.lang.reflect.Constructor.constructNative(Native Method) 04-12 23:48:22.968: E/AndroidRuntime(1509): at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.view.LayoutInflater.createView(LayoutInflater.java:594) 04-12 23:48:22.968: E/AndroidRuntime(1509): ... 28 more 04-12 23:48:22.968: E/AndroidRuntime(1509): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f090104 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.content.res.Resources.getText(Resources.java:244) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.content.res.Resources.getString(Resources.java:330) 04-12 23:48:22.968: E/AndroidRuntime(1509): at android.content.Context.getString(Context.java:343) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.gh.lighting.widget.GhViewPager.init(GhViewPager.java:95) 04-12 23:48:22.968: E/AndroidRuntime(1509): at com.gh.lighting.widget.GhViewPager.<init>(GhViewPager.java:88) 04-12 23:48:22.968: E/AndroidRuntime(1509): ... 31 more 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览