App Crashes after moving an image button! android - android

So my app Ive been developing lately is going great, and I just updated the image in the background of the app. Well the app was working right before I tweaked an image button to line up with this image I made. Right after I moved it, the app will no longer work and I have tried everything with no success. Here is the xml of the activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/title_screen"
tools:context=".TitleScreen" >
<TextView
android:id="#+id/txtCoins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:layout_marginTop="11dp"
android:text="000"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#f3c50d"
android:textSize="12sp" />
<ImageButton
android:id="#+id/imageBtnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtCoins"
android:layout_centerHorizontal="true"
android:layout_marginTop="51dp"
android:background="#null"
android:src="#drawable/btn_play" />
</RelativeLayout>
EDIT: Here is my logcat
03-20 17:08:29.847: W/dalvikvm(28692): threadid=1: thread exiting with uncaught exception (group=0x416282a0)
03-20 17:08:29.852: E/AndroidRuntime(28692): FATAL EXCEPTION: main
03-20 17:08:29.852: E/AndroidRuntime(28692): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ChonBonStudios.Tidbits/com.ChonBonStudios.Tidbits.TitleScreen}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.os.Looper.loop(Looper.java:137)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-20 17:08:29.852: E/AndroidRuntime(28692): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 17:08:29.852: E/AndroidRuntime(28692): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 17:08:29.852: E/AndroidRuntime(28692): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
03-20 17:08:29.852: E/AndroidRuntime(28692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
03-20 17:08:29.852: E/AndroidRuntime(28692): at dalvik.system.NativeStart.main(Native Method)
03-20 17:08:29.852: E/AndroidRuntime(28692): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton
03-20 17:08:29.852: E/AndroidRuntime(28692): at com.ChonBonStudios.Tidbits.TitleScreen.onCreate(TitleScreen.java:20)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.Activity.performCreate(Activity.java:5191)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-20 17:08:29.852: E/AndroidRuntime(28692): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-20 17:08:29.852: E/AndroidRuntime(28692): ... 11 more

android.widget.TextView cannot be cast to android.widget.ImageButton
You are casting to the wrong class in your activity change TextView to ImageButton somewhere in com.ChonBonStudios.Tidbits.TitleScreen class.

this is a common issue. Clean your project by selecting Project - Clean and it will work. And like gpasci said, check if you initialize your fields correctly

If I understand you correctly you just have switched the position of the TextView and the ImageButton in the layout, no code changes.
Try to simply clean the project and/or restart Eclipse. Sometimes I had a similar problem where the auto-generated Ids were just ouf of sync and that's the reason why a findViewById(R.id.imageBtnPlay) actually returns the TextView.

Related

Android activity with TimePicker object in Japanese Locale crashing when device is rotated

I am experiencing an issue in my app where when user rotate the device when an actvity with time picker object in the layout, it crashes. We could only replicate in Japanese and other Asian locale only and app works fine in other languages. To rule out any issue on our side, I created a simple test activity that loads this layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
If I rotate the device, it works fine in English locale (or if android:visibility is not gone) but if device is in Japanese locale, app crashes with following exception:
07-23 21:46:02.939: E/AndroidRuntime(22524): FATAL EXCEPTION: main
07-23 21:46:02.939: E/AndroidRuntime(22524): Process: com.example.datepickertest, PID: 22524
07-23 21:46:02.939: E/AndroidRuntime(22524): java.lang.IndexOutOfBoundsException: setSpan (2 ... 2) ends beyond length 0
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.text.Selection.setSelection(Selection.java:76)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.widget.EditText.setSelection(EditText.java:87)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.widget.NumberPicker$SetSelectionCommand.run(NumberPicker.java:2123)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.os.Handler.handleCallback(Handler.java:733)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.os.Handler.dispatchMessage(Handler.java:95)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.os.Looper.loop(Looper.java:137)
07-23 21:46:02.939: E/AndroidRuntime(22524): at android.app.ActivityThread.main(ActivityThread.java:4998)
07-23 21:46:02.939: E/AndroidRuntime(22524): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 21:46:02.939: E/AndroidRuntime(22524): at java.lang.reflect.Method.invoke(Method.java:515)
07-23 21:46:02.939: E/AndroidRuntime(22524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-23 21:46:02.939: E/AndroidRuntime(22524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
07-23 21:46:02.939: E/AndroidRuntime(22524): at dalvik.system.NativeStart.main(Native Method)
Anyone else ever experienced this issue? Any input will be highly appreciated.
Thanks!
There are two possibilities which solved the problem in my case (for TimePicker or NumberPicker):
i.) call these methods in your onCreate after calling findViewbyID:
TimePicker.setSaveFromParentEnabled(false);
TimePicker.setSaveEnabled(false);
(found in https://stackoverflow.com/a/31702937/4240534)
ii.) set your TimePicker to INVISIBLE instead of GONE (if this is possible concerning your layout design)
<TimePicker code here
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />

TextView cause an error on android emulator

I create TextView and set it to show value of some variable. The problem occur when I run android emulator, the application start normally, but when I click on the screen to let TextView show on screen, it's error.
This is LogCat of this application.
03-20 11:38:02.871: D/dalvikvm(3662): GC_FOR_ALLOC freed 86K, 5% free 3047K/3200K, paused 55ms, total 57ms
03-20 11:38:02.901: I/dalvikvm-heap(3662): Grow heap (frag case) to 4.930MB for 1987216-byte allocation
03-20 11:38:02.951: D/dalvikvm(3662): GC_FOR_ALLOC freed 2K, 4% free 4985K/5144K, paused 42ms, total 42ms
03-20 11:38:03.981: I/Choreographer(3662): Skipped 30 frames! The application may be doing too much work on its main thread.
03-20 11:38:04.031: D/gralloc_goldfish(3662): Emulator without GPU emulation detected.
03-20 11:38:16.111: I/Choreographer(3662): Skipped 345 frames! The application may be doing too much work on its main thread.
03-20 11:38:22.541: W/ResourceType(3662): No package identifier when getting value for resource number 0x00000001
03-20 11:38:22.551: D/AndroidRuntime(3662): Shutting down VM
03-20 11:38:22.551: W/dalvikvm(3662): threadid=1: thread exiting with uncaught exception (group=0xb1af5ba8)
03-20 11:38:22.601: E/AndroidRuntime(3662): FATAL EXCEPTION: main
03-20 11:38:22.601: E/AndroidRuntime(3662): Process: com.example.yyy, PID: 3662
03-20 11:38:22.601: E/AndroidRuntime(3662): android.content.res.Resources$NotFoundException: String resource ID #0x1
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.content.res.Resources.getText(Resources.java:244)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.widget.TextView.setText(TextView.java:3888)
03-20 11:38:22.601: E/AndroidRuntime(3662): at com.example.yyy.Find2Activity.onClick(Find2Activity.java:167)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.view.View.performClick(View.java:4438)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.view.View$PerformClick.run(View.java:18422)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.os.Handler.handleCallback(Handler.java:733)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.os.Handler.dispatchMessage(Handler.java:95)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.os.Looper.loop(Looper.java:136)
03-20 11:38:22.601: E/AndroidRuntime(3662): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-20 11:38:22.601: E/AndroidRuntime(3662): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 11:38:22.601: E/AndroidRuntime(3662): at java.lang.reflect.Method.invoke(Method.java:515)
03-20 11:38:22.601: E/AndroidRuntime(3662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-20 11:38:22.601: E/AndroidRuntime(3662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-20 11:38:22.601: E/AndroidRuntime(3662): at dalvik.system.NativeStart.main(Native Method)
03-20 11:38:27.071: I/Process(3662): Sending signal. PID: 3662 SIG: 9
android.content.res.Resources$NotFoundException: String resource ID #0x1
The stacktrace is telling you that you are calling yourTextView.setText(1);, with 1
as int value. Change it to yourTextView.setText(""+1); to convert that value to String.
If you pass a int to setText android will try to look up for a String with id the int you provided

Binary XML file line #7: Error inflating class fragment

i do everything, research every but still not working. i read many page from here but not :(
I tried every solution.
Error logs:
03-20 14:46:49.627: I/Process(1895): Sending signal. PID: 1895 SIG: 9
03-20 14:46:59.608: E/Trace(1937): error opening trace file: No such file or directory (2)
03-20 14:46:59.608: W/Trace(1937): Unexpected value from nativeGetEnabledTags: 0
03-20 14:46:59.608: W/Trace(1937): Unexpected value from nativeGetEnabledTags: 0
03-20 14:46:59.608: W/Trace(1937): Unexpected value from nativeGetEnabledTags: 0
03-20 14:46:59.707: W/Trace(1937): Unexpected value from nativeGetEnabledTags: 0
03-20 14:46:59.707: W/Trace(1937): Unexpected value from nativeGetEnabledTags: 0
03-20 14:47:00.207: D/AndroidRuntime(1937): Shutting down VM
03-20 14:47:00.217: W/dalvikvm(1937): threadid=1: thread exiting with uncaught exception (group=0xb5dcc908)
03-20 14:47:00.327: E/AndroidRuntime(1937): FATAL EXCEPTION: main
03-20 14:47:00.327: E/AndroidRuntime(1937): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.panetest/com.example.panetest.PaneTest}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.os.Looper.loop(Looper.java:137)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-20 14:47:00.327: E/AndroidRuntime(1937): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 14:47:00.327: E/AndroidRuntime(1937): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 14:47:00.327: E/AndroidRuntime(1937): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 14:47:00.327: E/AndroidRuntime(1937): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 14:47:00.327: E/AndroidRuntime(1937): at dalvik.system.NativeStart.main(Native Method)
03-20 14:47:00.327: E/AndroidRuntime(1937): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-20 14:47:00.327: E/AndroidRuntime(1937): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Activity.setContentView(Activity.java:1881)
03-20 14:47:00.327: E/AndroidRuntime(1937): at com.example.panetest.PaneTest.onCreate(PaneTest.java:16)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Activity.performCreate(Activity.java:5104)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-20 14:47:00.327: E/AndroidRuntime(1937): ... 11 more
03-20 14:47:00.327: E/AndroidRuntime(1937): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.panetest.FirstPane: make sure class name exists, is public, and has an empty constructor that is public
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Fragment.instantiate(Fragment.java:592)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Fragment.instantiate(Fragment.java:560)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Activity.onCreateView(Activity.java:4709)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-20 14:47:00.327: E/AndroidRuntime(1937): ... 21 more
03-20 14:47:00.327: E/AndroidRuntime(1937): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.panetest.FirstPane" on path: /data/app/com.example.panetest-1.apk
03-20 14:47:00.327: E/AndroidRuntime(1937): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
03-20 14:47:00.327: E/AndroidRuntime(1937): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-20 14:47:00.327: E/AndroidRuntime(1937): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-20 14:47:00.327: E/AndroidRuntime(1937): at android.app.Fragment.instantiate(Fragment.java:582)
03-20 14:47:00.327: E/AndroidRuntime(1937): ... 24 more
activity_pane_test.xml
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/slidingpanelayout">
<fragment android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.panetest.FirstPane"
android:id="#+id/fragment_firstpane"/>
<fragment android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.panetest.SecondPane"
android:id="#+id/fragment_secondpane"/>
PaneTest.java
package com.example.panetest;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.Menu;
public class PaneTest extends Activity {
SlidingPaneLayout pane; #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pane_test);
pane = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pane_test, menu);
return true;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.panetest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.panetest.PaneTest"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Please anyone provide solution.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.panetest.FirstPane" on path: /data/app/com.example.panetest-1.apk
Your project does not seem to have a class FirstPane in package com.example.panetest.

Fatal Exception Main (unable to start activity) Caused by: java.lang.NullPointerException

i'm noob at android and i face a strange exception when i try to settext or setcolor or anything that was working before
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pageNoSeek = (SeekBar)findViewById(R.id.pageNoSeekBar);
pageNotv = (TextView)findViewById(R.id.pageNotv);
nextButton=(ImageButton)findViewById(R.id.leftButton);
backButton=(ImageButton)findViewById(R.id.rightButton);
mainText = (TextView)findViewById(R.id.mainText);
mainText.setTextColor(Color.RED);
}
as shown in code above there's nothing unusual .. acutally i've used this same code before at another machine .. it gives error at setTextColor or setTextSize if i added it..
> 03-20 07:55:17.552: E/AndroidRuntime(1718): FATAL EXCEPTION: main
03-20 07:55:17.552: E/AndroidRuntime(1718): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thedarkdimension.keyboardShortcut/com.thedarkdimension.keyboardShortcut.StoryViewController}: java.lang.NullPointerException
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.os.Looper.loop(Looper.java:137)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-20 07:55:17.552: E/AndroidRuntime(1718): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 07:55:17.552: E/AndroidRuntime(1718): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 07:55:17.552: E/AndroidRuntime(1718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-20 07:55:17.552: E/AndroidRuntime(1718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-20 07:55:17.552: E/AndroidRuntime(1718): at dalvik.system.NativeStart.main(Native Method)
03-20 07:55:17.552: E/AndroidRuntime(1718): Caused by: java.lang.NullPointerException
03-20 07:55:17.552: E/AndroidRuntime(1718): at com.thedarkdimension.keyboardShortcut.StoryViewController.getNextPage(StoryViewController.java:95)
03-20 07:55:17.552: E/AndroidRuntime(1718): at com.thedarkdimension.keyboardShortcut.StoryViewController.connectToDB(StoryViewController.java:84)
03-20 07:55:17.552: E/AndroidRuntime(1718): at com.thedarkdimension.keyboardShortcut.StoryViewController.onCreate(StoryViewController.java:47)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.Activity.performCreate(Activity.java:5104)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-20 07:55:17.552: E/AndroidRuntime(1718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-20 07:55:17.552: E/AndroidRuntime(1718): ... 11 more
and i can't get it .. can anyone help :)
From you code snippet for onCreate it seems that you have not called setContentView.
For this reason all calls for (X)findViewById(R.id.x); returns null and thus you are getting a Null Pointer Exception when you try to operate on the variables. [mainText is null since the view was not found].
Solution:
Call setContentView first and then initialize your variables and do the remaining stuff

Customize Android PreferenceFragment not working

Currently for my 2.x preference screens, in every PreferenceActivity I add the line setContentView(R.layout.activity_preferences); to have a custom layout in my activities.
The activity_preferences.xml layout file looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout style="#style/TitleBar">
<ImageButton style="#style/TitleBarAction"
android:src="#drawable/ic_title_home"
android:onClick="onHomeClick" />
<ImageView style="#style/TitleBarSeparator" />
<eu.vranckaert.worktime.utils.view.CustomTextView
style="#style/TitleBarText" android:text="#string/lbl_preferences_title"/>
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/list"/>
</LinearLayout>
For my 3.x and up application I am building the preferences according to the example over here: http://developer.android.com/reference/android/preference/PreferenceActivity.html.
In order to apply the same layout to my 3.x app, I tried was to add the setContentView(..) in the 3.x PreferenceActivity.
Result on phone: this works fine on the first activity, then when loading a fragment (with the real preferences in them) my style is not applied
Result on tablet: crash:
ERROR/AndroidRuntime(2208): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{eu.vranckaert.worktime/eu.vranckaert.worktime.activities.preferences.PreferencesICSActivity}: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{4101ed38 #0 id=0x10202d4}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{4101ed38 #0 id=0x10202d4}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
at android.app.BackStackRecord.run(BackStackRecord.java:622)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
at android.app.Activity.performStart(Activity.java:4474)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
... 11 more
When I try to apply the layout file on my fragments using getActivity().setContentView(R.layout.activity_preferences); the result is:
for phone: the activity is still shown fine, when going into a category it crashes:
ERROR/AndroidRuntime(1320): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{eu.vranckaert.worktime/eu.vranckaert.worktime.activities.preferences.PreferencesICSActivity}: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment DateTimePreferencesFragment{412a0d78 #0 id=0x10202d4}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x10202d4 for fragment TimeRegistrationsPreferencesFragment{412a0d78 #0 id=0x10202d4}
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
at android.app.BackStackRecord.run(BackStackRecord.java:622)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
at android.app.Activity.performStart(Activity.java:4474)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
... 11 more
for tablet: same crash as before...
How should I apply this layout file to my fragment activity...? Or should I create a new layout file?

Categories

Resources