I was trying to make android app for my radio station. I want when user will open the app the site will load automatically. I was following this tutorial
but when I tried to run the app it's showing this error "Unfortunately,Tarab Radio stop work "
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
& MainActivity.java
package com.jibon.tarabradio;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
#SuppressLint("SetJavaScriptEnabled") #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://hoicoimasti.com/radio/");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Any Idea where I did mistake. Thanks in advance.
put setContentView(R.layout.activity_main); in your onCreate method.
Related
I've add a webView in my android app, i want it to open in that webView, but the link always opens in the maps app..And don't suggest to use desktop view mode
package com.example.webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class YourActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://maps.google.com/maps?" + "saddr=43.0054446,-87.9678884" + "&daddr=42.9257104,-88.0508355");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
The layout file is
<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="com.example.webview.MainActivity$PlaceholderFragment" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
I think you can create the URL and open an intent. In this answer it explains how to do it
I am currently taking an Android course and I just learned about DDMS and debugging with Logcat.
However, the problem I have is that there are no outputs being shown on DDMS whenever I run the program on the emulator (using Eclipse IDE)
Here is my code
package com.fv.android.practice.project;
import java.io.FileOutputStream;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
public static final String DEBUGTAG = "FV";
public static final String TEXTFILE = "notesquirrel.txt";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addSaveButtonListener();
}
private void addSaveButtonListener() {
Button saveBtn = (Button) findViewById(R.id.save);
saveBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText editText = (EditText) findViewById(R.id.text);
String text = editText.getText().toString();
Log.d(DEBUGTAG, "Save button clicked: " + text);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
And XML
<LinearLayout 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:orientation="vertical" >
<EditText
android:id="#+id/text"
android:maxLength="400"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Enter Your Text Here" />
<Button
android:id="#+id/save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>
When I type something into the "note" app, I should have some sort of output saying that I typed something, but I have zero output from the DDMS. Nothing at all. What can I do to fix this? I already went to the manifest and tried to set Debuggable to true but Eclipse tells me not to hardcode the debugging process, or something like that.
Also, I checked to see if the emulator was selected for debugging in the DDMS, and it is.
Fixed the issue. Now using Android Studio.
Is there any way to display the code by the help of using textview. Here is my problem, when i write the code into android:text=" " of the textview it shows an error.I am just trying to show the code using textview.
Please help me
Error 1(Line 14):String literal is not properly closed by a double-quote
Error 2(line 20):Multiple markers at this line
- Illegal modifier for the local class MainActivity; only abstract or final is
permitted
- The nested type MainActivity cannot hide an enclosing type
Here is my xmlcode:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</FrameLayout>
Here is my Java Code:
package com.example.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.widget.TextView;
import com.example.han.R;
public class MainActivity extends ActionBarActivity {
TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView) findViewById(R.id.textView1);
tv.setText("package com.example.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import com.example.han.R;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}");
}
}
Getting an error with my webview code. Wanting to create a webview that would work on all android OS. Am i on the right path?
webview1 seems to be giving me trouble. Not sure exactly why. Any pointers would be appreciated. Thanks in advance.
main.java
package com.webapp.Area;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://www.area.com;";
WebView view = (WebView) this.findViewById(R.id.webview1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity.xml
<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"
tools:context=".MainActivity" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
</RelativeLayout>
This is what im staring at. :/
:) just need to change below line.
WebView view = (WebView) this.findViewById(R.id.webview1);
to
WebView view = (WebView) this.findViewById(R.id.webView1); // "V" should be in capital
package com.quinnco.PakageName;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.Feed);
myWebView.loadUrl("link two");
WebSettings websettings=myWebView.getSettings();
WebSettings.setJavaScriptEnabled(true);
WebView myWebView = (WebView) findViewById(R.id.Chat);
myWebView.loadUrl("link one");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
<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" >
<WebView
android:id="#+id/Chat"
android:layout_width="fill_parent"
android:layout_height="175dp"
android:layout_alignLeft="#+id/Feed"
android:layout_alignParentTop="true" />
<WebView
android:id="#+id/Feed"
android:layout_width="fill_parent"
android:layout_height="175dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/Chat" />
</RelativeLayout>
I made this so that It wont get stolen just in case
All link and pakage names are changed I know that just help wiht the main ActivityMain.Java
The two webviews are on the same page and I dont know how to do this. Please help
You are trying to use the same name for two different webviews. Change one of them to something else, like myWebView_Bottom or something