I wrote an android program. This has multiple tab.. I want when I clicked a tab(Tab1), the tab's special view(GalleryDemoActivity.java) was shown.. But the Program has stopped working and does'nt work truly !
The code is:
src/Tab.java:
package com.AdMd.Plant;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Tabs extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
setContentView(R.layout.tabs);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Tab 1");
Intent photosIntent = new Intent(this, GalleryDemoActivity.class);
spec1.setContent(photosIntent);
spec1.setIndicator("اطلاعات گیاه");
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("گالری تصاویر");
spec2.setContent(R.id.tab2);
TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setIndicator("گیاهان مشابه");
spec3.setContent(R.id.tab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
The logcat messages are:
07-18 08:32:37.402: D/gralloc_goldfish(1068): Emulator without GPU emulation detected.
07-18 08:32:40.272: D/AndroidRuntime(1068): Shutting down VM
07-18 08:32:40.272: W/dalvikvm(1068): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
07-18 08:32:40.344: E/AndroidRuntime(1068): FATAL EXCEPTION: main
07-18 08:32:40.344: E/AndroidRuntime(1068): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.AdMd.Plant/com.AdMd.Plant.Tabs}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.os.Looper.loop(Looper.java:137)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 08:32:40.344: E/AndroidRuntime(1068): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 08:32:40.344: E/AndroidRuntime(1068): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 08:32:40.344: E/AndroidRuntime(1068): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 08:32:40.344: E/AndroidRuntime(1068): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 08:32:40.344: E/AndroidRuntime(1068): at dalvik.system.NativeStart.main(Native Method)
07-18 08:32:40.344: E/AndroidRuntime(1068): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.widget.TabHost.setCurrentTab(TabHost.java:346)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.widget.TabHost.addTab(TabHost.java:236)
07-18 08:32:40.344: E/AndroidRuntime(1068): at com.AdMd.Plant.Tabs.onCreate(Tabs.java:32)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.Activity.performCreate(Activity.java:4465)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 08:32:40.344: E/AndroidRuntime(1068): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 08:32:40.344: E/AndroidRuntime(1068): ... 11 more
As you see in logcat, it said to me to have a activity Group, But when I use it, the program has some warning and it does'nt work again!
The warning are:
1.The method onCreate(Bundle) from the type ActivityGroup is deprecated
2.The type ActivityGroup is deprecated
What should I've done?
Thanks..
you have to provide action for every tab
just try this code
public class Tabs extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
setContentView(R.layout.tabs);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setIndicator("اطلاعات گیاه");
spec1.setContent(new Intent(this,GalleryDemoActivity.class));
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("گالری تصاویر");
spec2.setContent(new Intent(this,GalleryDemoActivity.class));
TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setIndicator("گیاهان مشابه");
spec3.setContent(new Intent(this,GalleryDemoActivity.class));
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
I am trying to create an android game, similar to the STROOP EFFECT.
In my first step I am attempting to create a HashMap with strings of colors as the key and their corresponding android color as the value. I.e:
HashMap<String, Integer> colors= new HashMap<>();
colors.put("Green", Color.GREEN);
colors.put("Blue", Color.BLUE);
colors.put("Red", Color.RED);
colors.put("Yellow", Color.YELLOW);
colors.put("Black", Color.BLACK);
I then convert both the keyset and the values to an array. (see code below)
What I am having trouble implementing is setting the Textview (where the string will be shown) to show a random String from the array and also to set this string to a random color from the color array. When I attempt to do my app crashes and I get the following error:
07-27 22:36:00.192: E/AndroidRuntime(32079): FATAL EXCEPTION: main
07-27 22:36:00.192: E/AndroidRuntime(32079): Process: com.example.brianapp, PID: 32079
07-27 22:36:00.192: E/AndroidRuntime(32079): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.brianapp/com.example.brianapp.Stroop}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=2
07-27 22:36:00.192: E/AndroidRuntime(32079): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
07-27 22:36:00.192: E/AndroidRuntime(32079): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
Current activity code:
public class Stroop extends ActionBarActivity {
HashMap<String, Integer> colors= new HashMap<>();
//putting the strings of the hasmap to an array
Object stringOnScreen[]= colors.keySet().toArray();
Object colorsOnScreen[]= colors.values().toArray();
TextView color;
Button btn1;
Button btn2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stroop);
Log.d("test", "test: " + stringOnScreen[2].toString()); //trace code
}//oncreate end
public void setUpQuestion(){
//set the text of the string in textview for user to see
color.setText("" + stringOnScreen[randInt(0, 4)]);
color.setTextColor((int) colorsOnScreen[randInt(0,4)]);
}
public void setUpGame(){
// setting up the hashmap
colors.put("Green", Color.GREEN);
colors.put("Blue", Color.BLUE);
colors.put("Red", Color.RED);
colors.put("Yellow", Color.YELLOW);
colors.put("Black", Color.BLACK);
// setting up vars
color = (TextView) findViewById(R.id.tvStroopColor);
btn1 = (Button) findViewById(R.id.btnStroop1);
btn2 = (Button) findViewById(R.id.btnStroop2);
}
/**
* method to get a random int
* #param min
* #param max
* #return
*/
public static int randInt(int min, int max) {
// NOTE: Usually this should be a field rather than a method
// variable so that it is not re-seeded every call.
Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
}
How can I implement this functionality? Any help would be great!
ATTEMPTED SOLUTION:
public class Stroop extends ActionBarActivity {
HashMap<String, Integer> colors= new HashMap<>();
//putting the strings of the hahsmap to an array
Object stringOnScreen[]= colors.keySet().toArray();
Object colorsOnScreen[]= colors.values().toArray();
TextView color;
Button btn1;
Button btn2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stroop);
setUpGame();
setUpQuestion();
}//oncreate end
public void setUpQuestion(){
int randString= new Random().nextInt(stringOnScreen.length);
int randColor= new Random().nextInt(colorsOnScreen.length);
//set the text of the string in textview for user to see
color.setText("" + stringOnScreen[randString]);
color.setTextColor(randColor);
}
public void setUpGame(){
// setting up the hashmap
colors.put("Green", Color.GREEN);
colors.put("Blue", Color.BLUE);
colors.put("Red", Color.RED);
colors.put("Yellow", Color.YELLOW);
colors.put("Black", Color.BLACK);
// setting up vars
color = (TextView) findViewById(R.id.tvStroopColor);
btn1 = (Button) findViewById(R.id.btnStroop1);
btn2 = (Button) findViewById(R.id.btnStroop2);
}
}
Now getting the following Logcat error report:
07-27 23:11:22.482: E/AndroidRuntime(11902): FATAL EXCEPTION: main
07-27 23:11:22.482: E/AndroidRuntime(11902): Process: com.example.brianapp, PID: 11902
07-27 23:11:22.482: E/AndroidRuntime(11902): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.brianapp/com.example.brianapp.Stroop}: java.lang.IllegalArgumentException: n <= 0: 0
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread.access$900(ActivityThread.java:161)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.os.Handler.dispatchMessage(Handler.java:102)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.os.Looper.loop(Looper.java:157)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread.main(ActivityThread.java:5356)
07-27 23:11:22.482: E/AndroidRuntime(11902): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 23:11:22.482: E/AndroidRuntime(11902): at java.lang.reflect.Method.invoke(Method.java:515)
07-27 23:11:22.482: E/AndroidRuntime(11902): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
07-27 23:11:22.482: E/AndroidRuntime(11902): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
07-27 23:11:22.482: E/AndroidRuntime(11902): at dalvik.system.NativeStart.main(Native Method)
07-27 23:11:22.482: E/AndroidRuntime(11902): Caused by: java.lang.IllegalArgumentException: n <= 0: 0
07-27 23:11:22.482: E/AndroidRuntime(11902): at java.util.Random.nextInt(Random.java:175)
07-27 23:11:22.482: E/AndroidRuntime(11902): at com.example.brianapp.Stroop.setUpQuestion(Stroop.java:51)
07-27 23:11:22.482: E/AndroidRuntime(11902): at com.example.brianapp.Stroop.onCreate(Stroop.java:42)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.Activity.performCreate(Activity.java:5426)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
07-27 23:11:22.482: E/AndroidRuntime(11902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
07-27 23:11:22.482: E/AndroidRuntime(11902): ... 11 more
Note lines:
07-27 23:11:22.482: E/AndroidRuntime(11902): Caused by: java.lang.IllegalArgumentException: n <= 0: 0
07-27 23:11:22.482: E/AndroidRuntime(11902): at java.util.Random.nextInt(Random.java:175)
07-27 23:11:22.482: E/AndroidRuntime(11902): at com.example.brianapp.Stroop.setUpQuestion(Stroop.java:51)
07-27 23:11:22.482: E/AndroidRuntime(11902): at
As your log says, your array index is out of bounds, because your array is empty. Initialize stringOnScreen and colorOnScreen AFTER calling setUpGame and do both before accessing the array.
public class Stroop extends ActionBarActivity {
HashMap<String, Integer> colors = new HashMap<>();
Object stringOnScreen[];
Object colorsOnScreen[];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stroop);
setUpGame()
stringOnScreen = colors.keySet().toArray();
colorOnScreen = colors.values().toArray();
Log.d("test", "test: " + stringOnScreen[2].toString());
}
...
}
i have a button in my app that i want to when i press button app send a string to websrvice and get the result , this is my code :
btn = (Button) findViewById(R.id.button_add_to_cart);
btn.setTypeface(typeface);
btn.setEnabled(false);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
env.encodingStyle="utf-8";
request = new SoapObject("customWebService",
"add");
request.addProperty("sessionID", sessionId);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(
"http://mywebsiteee.com/WebService/server.php?wsdl/",
60000);
androidHttpTransport.debug = true;
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.call("", env);
SoapObject result = (SoapObject)env.bodyIn;
String Test1 = result.getPropertyAsString(0);
String str = env.bodyIn.toString();
String s = Test1;
byte[] b = s.getBytes("UTF-8");
s = new String(b, "UTF-8");
try {
JSONObject jsonObject = new JSONObject(Test1);
s = jsonObject.getString("result");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
my problem is when i press button first time i get this error :
java.io.EOFException
this is full log :
07-27 07:47:25.059: W/System.err(1251): java.io.EOFException
07-27 07:47:25.059: W/System.err(1251): at libcore.io.Streams.readAsciiLine(Streams.java:203)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.ServiceConnectionSE.getResponseCode(ServiceConnectionSE.java:103)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
07-27 07:47:25.059: W/System.err(1251): at com.tashilgostar.tashilgostarstore.ProductActivity$5.onClick(ProductActivity.java:294)
07-27 07:47:25.059: W/System.err(1251): at android.view.View.performClick(View.java:4240)
07-27 07:47:25.059: W/System.err(1251): at android.view.View$PerformClick.run(View.java:17721)
07-27 07:47:25.059: W/System.err(1251): at android.os.Handler.handleCallback(Handler.java:730)
07-27 07:47:25.059: W/System.err(1251): at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 07:47:25.059: W/System.err(1251): at android.os.Looper.loop(Looper.java:137)
07-27 07:47:25.059: W/System.err(1251): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-27 07:47:25.059: W/System.err(1251): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 07:47:25.059: W/System.err(1251): at java.lang.reflect.Method.invoke(Method.java:525)
07-27 07:47:25.059: W/System.err(1251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-27 07:47:25.059: W/System.err(1251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-27 07:47:25.059: W/System.err(1251): at dalvik.system.NativeStart.main(Native Method)
but after some time i press button or when i press it long time it`s work correctly !
can any body help me know why this happen ?
It worked setting the header property "Connection".
ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
transport.call(SOAP_ACTION, envelope, headerPropertyArrayList);
https://code.google.com/p/ksoap2-android/issues/detail?id=173&can=1&start=100
The code below ends in a nullPointerException when run.
The logcat is first, the code is second.
Logcat:
07-27 09:58:13.705: D/AndroidRuntime(18164): Shutting down VM
0
7-27 09:58:13
.705: W/dalvikvm(18164): threadid=1: thread exiting with uncaught exception (group=0x40a3c1f8)
07-27 09:58:13.710: E/AndroidRuntime(18164): FATAL EXCEPTION: main
07-27 09:58:13.710: E/AndroidRuntime(18164): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liamwli.smsbusy/com.liamwli.smsbusy.Sms_busyActivity}: java.lang.NullPointerException
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.os.Looper.loop(Looper.java:137)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread.main(ActivityThread.java:4575)
07-27 09:58:13.710: E/AndroidRuntime(18164): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 09:58:13.710: E/AndroidRuntime(18164): at java.lang.reflect.Method.invoke(Method.java:511)
07-27 09:58:13.710: E/AndroidRuntime(18164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-27 09:58:13.710: E/AndroidRuntime(18164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-27 09:58:13.710: E/AndroidRuntime(18164): at dalvik.system.NativeStart.main(Native Method)
07-27 09:58:13.710: E/AndroidRuntime(18164): Caused by: java.lang.NullPointerException
07-27 09:58:13.710: E/AndroidRuntime(18164): at com.liamwli.smsbusy.Sms_busyActivity.doCheck(Sms_busyActivity.java:142)
07-27 09:58:13.710: E/AndroidRuntime(18164): at com.liamwli.smsbusy.Sms_busyActivity.onCreate(Sms_busyActivity.java:60)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.Activity.performCreate(Activity.java:4465)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-27 09:58:13.710: E/AndroidRuntime(18164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
07-27 09:58:13.710: E/AndroidRuntime(18164): ... 11 more
07-27 09:58:14.035: I/dalvikvm(18164): threadid=3: reacting to signal 3
07-27 09:58:14.055: I/dalvikvm(18164): Wrote stack traces to '/data/anr/traces.txt'
07-27 09:58:14.260: I/dalvikvm(18164): threadid=3: reacting to signal 3
07-27 09:58:14.275: I/dalvikvm(18164): Wrote stack traces to '/data/anr/traces.txt'
07-27 10:01:17.450: D/AndroidRuntime(18326): Shutting down VM
07-27 10:01:17.455: W/dalvikvm(18326): threadid=1: thread exiting with uncaught exception (group=0x40a3c1f8)
07-27 10:01:17.455: E/AndroidRuntime(18326): FATAL EXCEPTION: main
07-27 10:01:17.455: E/AndroidRuntime(18326): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liamwli.smsbusy/com.liamwli.smsbusy.Sms_busyActivity}: java.lang.NullPointerException
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.os.Looper.loop(Looper.java:137)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread.main(ActivityThread.java:4575)
07-27 10:01:17.455: E/AndroidRuntime(18326): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 10:01:17.455: E/AndroidRuntime(18326): at java.lang.reflect.Method.invoke(Method.java:511)
07-27 10:01:17.455: E/AndroidRuntime(18326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-27 10:01:17.455: E/AndroidRuntime(18326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-27 10:01:17.455: E/AndroidRuntime(18326): at dalvik.system.NativeStart.main(Native Method)
07-27 10:01:17.455: E/AndroidRuntime(18326): Caused by: java.lang.NullPointerException
07-27 10:01:17.455: E/AndroidRuntime(18326): at com.liamwli.smsbusy.Sms_busyActivity.doCheck(Sms_busyActivity.java:142)
07-27 10:01:17.455: E/AndroidRuntime(18326): at com.liamwli.smsbusy.Sms_busyActivity.onCreate(Sms_busyActivity.java:60)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.Activity.performCreate(Activity.java:4465)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-27 10:01:17.455: E/AndroidRuntime(18326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
07-27 10:01:17.455: E/AndroidRuntime(18326): ... 11 more
07-27 10:01:17.855: I/dalvikvm(18326): threadid=3: reacting to signal 3
07-27 10:01:17.860: I/dalvikvm(18326): Wrote stack traces to '/data/anr/traces.txt'
07-27 10:01:17.990: I/dalvikvm(18326): threadid=3: reacting to signal 3
07-27 10:01:17.995: I/dalvikvm(18326): Wrote stack traces to '/data/anr/traces.txt'
07-27 10:04:32.645: D/AndroidRuntime(18561): Shutting down VM
07-27 10:04:32.645: W/dalvikvm(18561): threadid=1: thread exiting with uncaught exception (group=0x40a3c1f8)
07-27 10:04:32.645: E/AndroidRuntime(18561): FATAL EXCEPTION: main
07-27 10:04:32.645: E/AndroidRuntime(18561): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liamwli.smsbusy/com.liamwli.smsbusy.Sms_busyActivity}: java.lang.NullPointerException
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.os.Looper.loop(Looper.java:137)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread.main(ActivityThread.java:4575)
07-27 10:04:32.645: E/AndroidRuntime(18561): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 10:04:32.645: E/AndroidRuntime(18561): at java.lang.reflect.Method.invoke(Method.java:511)
07-27 10:04:32.645: E/AndroidRuntime(18561): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-27 10:04:32.645: E/AndroidRuntime(18561): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-27 10:04:32.645: E/AndroidRuntime(18561): at dalvik.system.NativeStart.main(Native Method)
07-27 10:04:32.645: E/AndroidRuntime(18561): Caused by: java.lang.NullPointerException
07-27 10:04:32.645: E/AndroidRuntime(18561): at com.liamwli.smsbusy.Sms_busyActivity.doCheck(Sms_busyActivity.java:140)
07-27 10:04:32.645: E/AndroidRuntime(18561): at com.liamwli.smsbusy.Sms_busyActivity.onCreate(Sms_busyActivity.java:58)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.Activity.performCreate(Activity.java:4465)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-27 10:04:32.645: E/AndroidRuntime(18561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
07-27 10:04:32.645: E/AndroidRuntime(18561): ... 11 more
07-27 10:04:33.060: I/dalvikvm(18561): threadid=3: reacting to signal 3
07-27 10:04:33.065: I/dalvikvm(18561): Wrote stack traces to '/data/anr/traces.txt'
07-27 10:04:33.185: I/dalvikvm(18561): threadid=3: reacting to signal 3
07-27 10:04:33.215: I/dalvikvm(18561): Wrote stack traces to '/data/anr/traces.txt'
07-27 10:04:36.915: I/Process(18561): Sending signal. PID: 18561 SIG: 9
Line 140 is the mChecker.checkAccess line new line under the last bracket:
private void doCheck() {
mChecker.checkAccess(mLicenseCheckerCallback);
}
Line 58 is the call to the doCheck method:
doCheck();
The rest of the class is below:
package com.liamwli.smsbusy;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.StrictPolicy;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
public class Sms_busyActivity extends Activity {
IntentFilter intentFilter;
ToggleButton endis;
EditText message;
Button smessage;
SharedPreferences getPrefs;
SharedPreferences.Editor editor;
private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;
private Handler mHandler;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String android_id = Secure.getString(getBaseContext()
.getContentResolver(), Secure.ANDROID_ID);
// if (!android_id.contentEquals("56d330123953677d")) {
// Log.e("SMS Busy App", "Device ID not allowed. Exiting.");
// finish();
// } else {
// Log.d("SMS Busy App", "Device ID Allowed");
// }
// Intent i = new Intent("com.liamwli.smsbusy.PREFS");
// startActivity(i);
setContentView(R.layout.def);
doCheck();
String KEY = "abcdefgijklmnopqrstuvqxyz"; //made up to post online
endis = (ToggleButton) findViewById(R.id.enableddis);
smessage = (Button) findViewById(R.id.savemess);
message = (EditText) findViewById(R.id.message);
getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
editor = getPrefs.edit();
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
final byte[] SALT = new byte[] { -46, 65, 30, -128, -103, -57, 74, -64,
51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64, 89 };
mChecker = new LicenseChecker(this, new StrictPolicy(), KEY);
mHandler = new Handler();
// ---intent to filter for SMS messages received---
intentFilter = new IntentFilter();
intentFilter.addAction("SMS_RECEIVED_ACTION");
Boolean state = getPrefs.getBoolean("enabled", false);
// String stext = getPrefs.getString("text", "");
// message.setText(stext);
message.setText(getPrefs.getString("text", ""));
if (message.getText().toString().contentEquals("")) {
Toast.makeText(this, "Unable to get saved message. Please resave.",
Toast.LENGTH_LONG).show();
}
endis.setChecked(state);
endis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Log.d("SMS Busy App", "onCheckedChanged Called");
// Toast.makeText(Sms_busyActivity.this, "App state changed",
// Toast.LENGTH_LONG).show();
editor = getPrefs.edit();
if (endis.isChecked()) {
editor.putBoolean("enabled", true);
} else {
editor.putBoolean("enabled", false);
}
editor.putString("text", message.getText().toString());
editor.commit();
}
});
smessage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
editor = getPrefs.edit();
editor.putString("text", message.getText().toString());
editor.commit();
Log.d("smessage", "Message saved & commited");
Toast.makeText(Sms_busyActivity.this, "Message Saved",
Toast.LENGTH_SHORT).show();
}
});
}
private void doCheck() {
mChecker.checkAccess(mLicenseCheckerCallback);
}
#SuppressWarnings("deprecation")
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
Log.d("SMS Busy App", "onKeyDown Called");
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
// public void onBackPressed() {
// Log.d("SMS Busy App", "onBackPressed Called");
// finish();
// }
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
Log.d("SMS Busy App", "onCreateOptionsMenu Called");
getMenuInflater().inflate(R.menu.mmenu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.aboutme:
Intent i = new Intent(this, AboutMe.class);
startActivity(i);
break;
}
return true;
}
private void displayResult(final String result) {
mHandler.post(new Runnable() {
public void run() {
Button mCheckLicenseButton = (Button) findViewById(R.id.button1);
mCheckLicenseButton.setText("App Licenced. Click to continue.");
mCheckLicenseButton.setEnabled(true);
setContentView(R.layout.main);
setProgressBarIndeterminateVisibility(false);
}
});
}
class MyLicenseCheckerCallback extends Activity implements
LicenseCheckerCallback {
public void allow(int reason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
displayResult(getString(R.string.allow));
}
#SuppressWarnings("deprecation")
public void dontAllow(int reason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
AlertDialog alert = new AlertDialog.Builder(Sms_busyActivity.this)
.create();
if (reason == Policy.RETRY) {
// If the reason received from the policy is RETRY, it was
// probably
// due to a loss of connection with the service, so we should
// give the
// user a chance to retry. So show a dialog to retry.
alert.setTitle("Please retry license check");
alert.setMessage("The connection to the licensing server was lost. Please click retry below");
alert.setButton("Retry", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
alert.show();
} else {
// Otherwise, the user is not licensed to use this app.
// Your response should always inform the user that the
// application
// is not licensed, but your behavior at that point can vary.
// You might
// provide the user a limited access version of your app or you
// can
// take them to Google Play to purchase the app.f
setContentView(R.layout.def);
alert.setTitle("Not Licensed");
alert.setMessage("This app is not licensed. Please buy it off google play.");
alert.setButton("Exit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
alert.show();
}
}
#Override
public void applicationError(int errorCode) {
// TODO Auto-generated method stub
}
}
}
EDIT: Line numbers were off. New logcat generated. Please look again.
You initialise you mChecker after using it :
mChecker = new LicenseChecker(this, new StrictPolicy(), KEY);
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
doCheck();
String KEY = "abcdefgijklmnopqrstuvqxyz"; //made up to post online
endis = (ToggleButton) findViewById(R.id.enableddis);
smessage = (Button) findViewById(R.id.savemess);
message = (EditText) findViewById(R.id.message);
getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
editor = getPrefs.edit();
final byte[] SALT = new byte[] { -46, 65, 30, -128, -103, -57, 74, -64,
51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64, 89 };
put below line before you call doCheck() method
mChecker = new LicenseChecker(this, new StrictPolicy(), KEY);
accoding to your onCreate(), it should look like
setContentView(R.layout.def);
String KEY = "abcdefgijklmnopqrstuvqxyz"; //Because u are using key in next line hence move Key before next line
mChecker = new LicenseChecker(this, new StrictPolicy(), KEY);// <<<THIS LINE SHOULD COME BEFORE doCheck CALLED
doCheck();
and setContentView(R.layout.def); should be moved just after super call in oncreate.
LogCat:
05-18 13:35:31.954: INFO/ActivityManager(51): Starting activity: Intent { cmp=elf.app/.RoomInfoActivity (has extras) }
05-18 13:35:32.535: WARN/ActivityManager(51): Activity pause timeout for HistoryRecord{44e19170 elf.app/.RoomListActivity}
05-18 13:35:37.623: WARN/WindowManager(51): Key dispatching timed out sending to elf.app/elf.app.RoomListActivity
05-18 13:35:37.623: WARN/WindowManager(51): Dispatch state: null
05-18 13:35:37.634: WARN/WindowManager(51): Current state: {{null to Window{44e364d8 elf.app/elf.app.RoomListActivity paused=false} # 1305725737637 lw=null lb=null fin=true gfw=true ed=true tts=0 wf=false fp=false mcf=null}}
05-18 13:35:37.634: WARN/WindowManager(51): Continuing to wait for key to be dispatched
05-18 13:35:37.664: WARN/WindowManager(51): No window to dispatch pointer action 0
05-18 13:35:37.674: WARN/WindowManager(51): No window to dispatch pointer action 1
05-18 13:35:42.018: WARN/ActivityManager(51): Launch timeout has expired, giving up wake lock!
05-18 13:35:42.608: WARN/ActivityManager(51): Activity idle timeout for HistoryRecord{44e1eff0 elf.app/.RoomInfoActivity}
05-18 13:35:43.434: DEBUG/dalvikvm(51): threadid=15: bogus mon 1+0>0; adjusting
05-18 13:37:03.754: DEBUG/AndroidRuntime(219): Shutting down VM
05-18 13:37:03.754: WARN/dalvikvm(219): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-18 13:37:05.425: ERROR/AndroidRuntime(219): Uncaught handler: thread main exiting due to uncaught exception
05-18 13:37:05.554: ERROR/AndroidRuntime(219): java.lang.RuntimeException: Unable to start activity ComponentInfo{elf.app/elf.app.RoomInfoActivity}: java.lang.NullPointerException
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.os.Looper.loop(Looper.java:123)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at java.lang.reflect.Method.invoke(Method.java:521)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at dalvik.system.NativeStart.main(Native Method)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): Caused by: java.lang.NullPointerException
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at elf.app.RoomInfoActivity.onCreate(RoomInfoActivity.java:39)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-18 13:37:05.554: ERROR/AndroidRuntime(219): ... 11 more
05-18 13:37:05.724: INFO/Process(51): Sending signal. PID: 219 SIG: 3
05-18 13:37:05.736: INFO/dalvikvm(219): threadid=7: reacting to signal 3
05-18 13:37:05.736: ERROR/dalvikvm(219): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-18 13:37:06.025: INFO/ARMAssembler(51): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x40d678:0x40d734] in 855613 ns
05-18 13:37:06.094: INFO/ARMAssembler(51): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x41eee8:0x41f0b0] in 1649122 ns
Code:
package elf.app;
import elf.app.comm.CommClientMod;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
* displays details about the selected room
*/
public class RoomInfoActivity extends Activity implements OnClickListener {
TextView rumInfo;
CharSequence rumInfoText;
Button buttonCleaned;
CharSequence buttonCleanedText;
TextView rumStatus;
CharSequence rumStatusText;
CommClientMod comm;
boolean cleaned = false;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.room_info);
comm = new CommClientMod("127.0.0.1", 62626);
rumInfo = (TextView)findViewById(R.id.textInfo);
buttonCleaned = (Button)findViewById(R.id.buttonCleaned);
rumStatus = (TextView)findViewById(R.id.textStatus);
rumInfoText = (CharSequence)getIntent().getExtras().getString("entry");
rumInfo.setText(rumInfoText);
buttonCleanedText = "Färdig med städningen";
buttonCleaned.setText(buttonCleanedText);
rumStatusText = (CharSequence)"Status: "+checkStatus();
rumStatus.setText(rumStatusText);
}
public void onClick(View v) {
if(v.equals(buttonCleaned)) {
if(cleaned==false) {
cleaned=true;
comm.send("skicka meddelande rummet är städat");
}
else {
cleaned=false;
comm.send("skicka meddelande rummet är inte städat");
}
}
}
public String checkStatus() {
if(cleaned==false)
return "Ej städat";
else
return "Städat";
}
}
Don't really understand why I'm getting a RuntimeException here..
if the line numbers from the code match your pastebin, it appears buttonCleaned = (Button)findViewById(R.id.buttonCleaned); is not finding that view. Does it exist in R.layout.room_info?
Just make a note that you have to put the setContentView(...) before using any component (e.g a button) belong to that view. Otherwise, the null exception will be raised.