Issue
So I've built this simple app as part of a self guided learn android class I'm taking. And it worked fine up until I made some changes to the Java file and then tried to reinstall and launch again. From the research I've done I think it has something to do with the manifest, but I'm not sure what is wrong. If you need to see anything else just ask. I'm really stumped on this. It was working up until I added the switch statement. It had been an if else
cluster and I was told to try and do it with a switch statement
. It appears to check out in eclipse but I just can't figure this out. Here is the logcat output.
01-22 07:43:12.106: E/libprocessgroup(1717): failed to make and chown /acct/uid_10054: Read-only file system 01-22 07:43:12.106: W/Zygote(1717): createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT? 01-22 07:43:12.107: I/art(1717): Not late-enabling -Xcheck:jni (already on) 01-22 07:43:12.192: D/AndroidRuntime(1717): Shutting down VM 01-22 07:43:12.192: D/AndroidRuntime(1717): --------- beginning of crash 01-22 07:43:12.193: E/AndroidRuntime(1717): FATAL EXCEPTION: main 01-22 07:43:12.193: E/AndroidRuntime(1717): Process: com.codeherenow.trafficlights, PID: 1717 01-22 07:43:12.193: E/AndroidRuntime(1717): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.codeherenow.trafficlights/com.codeherenow.trafficlights.TrafficLightsActivity}: java.lang.InstantiationException: class com.codeherenow.trafficlights.TrafficLightsActivity cannot be instantiated 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread.access$800(ActivityThread.java:144) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.os.Handler.dispatchMessage(Handler.java:102) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.os.Looper.loop(Looper.java:135) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread.main(ActivityThread.java:5221) 01-22 07:43:12.193: E/AndroidRuntime(1717): at java.lang.reflect.Method.invoke(Native Method) 01-22 07:43:12.193: E/AndroidRuntime(1717): at java.lang.reflect.Method.invoke(Method.java:372) 01-22 07:43:12.193: E/AndroidRuntime(1717): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 01-22 07:43:12.193: E/AndroidRuntime(1717): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 01-22 07:43:12.193: E/AndroidRuntime(1717): Caused by: java.lang.InstantiationException: class com.codeherenow.trafficlights.TrafficLightsActivity cannot be instantiated 01-22 07:43:12.193: E/AndroidRuntime(1717): at java.lang.Class.newInstance(Class.java:1553) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.Instrumentation.newActivity(Instrumentation.java:1065) 01-22 07:43:12.193: E/AndroidRuntime(1717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199) 01-22 07:43:12.193: E/AndroidRuntime(1717): ... 10 more 01-22 07:48:13.660: I/Process(1717): Sending signal. PID: 1717 SIG: 9
And here is the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codeherenow.trafficlights"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="com.codeherenow.trafficlights.TrafficLightsActivity"
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>
Here is the java:
package com.codeherenow.trafficlights;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public abstract class TrafficLightsActivity extends Activity implements OnClickListener {
private ImageView redLight;
private ImageView yellowLight;
private ImageView greenLight;
private Button redButton;
private Button yellowButton;
private Button greenButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.traffic_lights);
redLight=(ImageView) findViewById(R.id.red_light);
yellowLight=(ImageView) findViewById(R.id.yellow_light);
greenLight=(ImageView) findViewById(R.id.green_light);
redButton=(Button) findViewById(R.id.Red_Button);
yellowButton=(Button) findViewById(R.id.Yellow_Button);
greenButton=(Button) findViewById(R.id.Green_Button);
redButton.setOnClickListener(this);
yellowButton.setOnClickListener(this);
greenButton.setOnClickListener(this);
redLight.setOnClickListener(this);
yellowLight.setOnClickListener(this);
greenLight.setOnClickListener(this);
}
public void onClick (View v) {
int v2=v.getId();
turnOffLight();
// TODO Auto-generated method stub
switch(v2){
case R.id.Red_Button:case R.id.red_light:
turnOnRedLight();
break;
case R.id.Yellow_Button: case R.id.yellow_light:
turnOnYellowLight();
break;
case R.id.Green_Button: case R.id.green_light:
turnOnGreenLight();
break;
default:
break;
}
}
private void turnOffLight() {
// TODO Auto-generated method stub
redLight.setImageResource(R.drawable.light_off);
greenLight.setImageResource(R.drawable.light_off);
yellowLight.setImageResource(R.drawable.light_off);
}
private void turnOnGreenLight() {
// TODO Auto-generated method stub
greenLight.setImageResource(R.drawable.green_on);
}
private void turnOnYellowLight() {
// TODO Auto-generated method stub
yellowLight.setImageResource(R.drawable.yellow_on);
}
private void turnOnRedLight() {
// TODO Auto-generated method stub
redLight.setImageResource(R.drawable.red_on);
}
}
Solution
public abstract class TrafficLightsActivity
and your error is Caused by: java.lang.InstantiationException:
..
solution is
public class TrafficLightsActivity
Answered By - Elltz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.