Hi guys,
I've been researching this, and I've seen a number of cases with the same issue, but none of their solutions have fit my problem.
All of my other buttons work perfectly, the one button that throws the exception is BackButton. I've got no idea why. I found 'Back' in R.id, it's been referenced correctly, there are no errors in the java file at all.
Here is my logcat report:
Here is my XML
activity_main:
Settings:
What are your thoughts?
Also, yes I know there are some empty spaces, I just haven't gotten around to writing those parts yet.
I've been researching this, and I've seen a number of cases with the same issue, but none of their solutions have fit my problem.
Code:
@Override
protected void onCreate(Bundle savedInstanceState)
{
....
ConnectButton = (Button)findViewById(R.id.Connect);
SettingsButton = (Button)findViewById(R.id.Settings);
CreditsButton = (Button)findViewById(R.id.Credits);
ExitButton = (Button)findViewById(R.id.Exit);
BackButton = (Button)findViewById(R.id.Back);
quality = (RadioGroup) findViewById(R.id.Quality);
ConnectButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
scanIP();
try
{
}
catch(RuntimeException r)
{
print(r.toString());
}
}
});
SettingsButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
setContentView(R.layout.settings);
}
});
/*Line 86*/ BackButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String selected = findViewById(quality.getCheckedRadioButtonId()).toString();
setQuality(selected);
setContentView(R.layout.activity_main);
}
});
CreditsButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
}
});
ExitButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
frontCam.release();
backCam.release();
}
catch(NullPointerException e){}
finish();
}
});
}
....
}
All of my other buttons work perfectly, the one button that throws the exception is BackButton. I've got no idea why. I found 'Back' in R.id, it's been referenced correctly, there are no errors in the java file at all.
Here is my logcat report:
Code:
09-11 21:53:35.732: E/AndroidRuntime(857): FATAL EXCEPTION: main
09-11 21:53:35.732: E/AndroidRuntime(857): java.lang.RuntimeException: Unable to start activity ComponentInfo{droidcam.assets/droidcam.assets.MainActivity}: java.lang.NullPointerException
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.os.Handler.dispatchMessage(Handler.java:99)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.os.Looper.loop(Looper.java:123)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-11 21:53:35.732: E/AndroidRuntime(857): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 21:53:35.732: E/AndroidRuntime(857): at java.lang.reflect.Method.invoke(Method.java:521)
09-11 21:53:35.732: E/AndroidRuntime(857): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-11 21:53:35.732: E/AndroidRuntime(857): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-11 21:53:35.732: E/AndroidRuntime(857): at dalvik.system.NativeStart.main(Native Method)
09-11 21:53:35.732: E/AndroidRuntime(857): Caused by: java.lang.NullPointerException
09-11 21:53:35.732: E/AndroidRuntime(857): at droidcam.assets.MainActivity.onCreate(MainActivity.java:86)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-11 21:53:35.732: E/AndroidRuntime(857): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-11 21:53:35.732: E/AndroidRuntime(857): ... 11 more
Here is my XML
activity_main:
Code:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<AbsoluteLayout
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:id="@+id/frontCamera"
android:layout_width="147dp"
android:layout_height="130dp"
android:visibility="invisible"
android:orientation="horizontal"
android:layout_x="0dp"
android:layout_y="1dp">
</TableRow>
<TableRow
android:id="@+id/backCamera"
android:layout_width="147dp"
android:layout_height="130dp"
android:visibility="invisible"
android:orientation="horizontal"
android:layout_x="173dp"
android:layout_y="1dp">
</TableRow>
<Button
android:id="@+id/Connect"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Connect to a Computer"
android:layout_x="60dp"
android:layout_y="169dp" />
<Button
android:id="@+id/Settings"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:text="Settings"
android:layout_x="95dp"
android:layout_y="222dp" />
<Button
android:id="@+id/Credits"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:text="Credits"
android:layout_x="96dp"
android:layout_y="275dp" />
<Button
android:id="@+id/Exit"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_x="84dp"
android:layout_y="330dp" />
</AbsoluteLayout>
</RelativeLayout>
Settings:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/frontCamera"
android:layout_width="147dp"
android:layout_height="130dp"
android:layout_x="0dp"
android:layout_y="1dp"
android:orientation="horizontal"
android:visibility="invisible" >
</TableRow>
<TableRow
android:id="@+id/backCamera"
android:layout_width="147dp"
android:layout_height="130dp"
android:visibility="invisible"
android:orientation="horizontal"
android:layout_x="173dp"
android:layout_y="1dp">
</TableRow>
<Button
android:id="@+id/Back"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:layout_x="84dp"
android:layout_y="330dp"
android:text="Main Menu" />
<RadioGroup
android:id="@+id/Quality"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="108dp"
android:layout_y="96dp" >
<RadioButton
android:id="@+id/VHigh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Very High" />
<RadioButton
android:id="@+id/High"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="High" />
<RadioButton
android:id="@+id/Balanced"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balanced" />
<RadioButton
android:id="@+id/Low"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Low" />
</RadioGroup>
<EditText
android:id="@+id/editText1"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_x="80dp"
android:layout_y="42dp"
android:clickable="false"
android:ems="10"
android:inputType="none"
android:text="Camera Quality:" >
<requestFocus />
</EditText>
</AbsoluteLayout>
</RelativeLayout>
Also, yes I know there are some empty spaces, I just haven't gotten around to writing those parts yet.